変数宣言を表します。
名前空間: System.CodeDom
アセンブリ: System (system.dll 内)
構文
'宣言
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class CodeVariableDeclarationStatement
Inherits CodeStatement
'使用
Dim instance As CodeVariableDeclarationStatement
[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class CodeVariableDeclarationStatement : CodeStatement
[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
public ref class CodeVariableDeclarationStatement : public CodeStatement
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
public class CodeVariableDeclarationStatement extends CodeStatement
SerializableAttribute
ComVisibleAttribute(true)
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
public class CodeVariableDeclarationStatement extends CodeStatement
解説
CodeVariableDeclarationStatement を使用して、変数を宣言するコードを表すことができます。
Type プロパティは、宣言する変数の型を指定します。Name プロパティは、宣言する変数の名前を指定します。InitExpression プロパティは省略可能で、変数を作成した後に割り当てを行うための初期化式を指定します。
注意
言語によっては、変数宣言の後に独立した代入ステートメントを記述することで、オプションの変数初期化式を実装できます。
使用例
CodeVariableDeclarationStatement を使用して変数を宣言する例を次に示します。
Dim variableDeclaration As New CodeVariableDeclarationStatement( _
GetType(String), "TestString", _
New CodePrimitiveExpression("Testing"))
' The first two parameters indicate the type and name of the variable to declare.
' The optional initExpression parameter initializes the variable.
' A Visual Basic code generator produces the following source code for the preceeding example code:
' Dim TestString As String = "Testing"
CodeVariableDeclarationStatement variableDeclaration = new CodeVariableDeclarationStatement(
// Type of the variable to declare.
typeof(string),
// Name of the variable to declare.
"TestString",
// Optional initExpression parameter initializes the variable.
new CodePrimitiveExpression("Testing") );
// A C# code generator produces the following source code for the preceeding example code:
// string TestString = "Testing";
// Type of the variable to declare.
// Name of the variable to declare.
// Optional initExpression parameter initializes the variable.
CodeVariableDeclarationStatement^ variableDeclaration = gcnew CodeVariableDeclarationStatement( String::typeid,"TestString",gcnew CodePrimitiveExpression( "Testing" ) );
// A C# code generator produces the following source code for the preceeding example code:
// string TestString = "Testing";
CodeVariableDeclarationStatement variableDeclaration =
new CodeVariableDeclarationStatement(
// Type of the variable to declare.
String.class.ToType(),
// Name of the variable to declare.
"TestString",
// Optional initExpression parameter initializes the variable.
new CodePrimitiveExpression("Testing"));
// A VJ# code generator produces the following source code for the
// preceeding example code:
// String testString = "Testing";
継承階層
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeVariableDeclarationStatement
スレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0