CodeVariableDeclarationStatement Class
Represents a variable declaration.
For a list of all members of this type, see CodeVariableDeclarationStatement Members.
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeVariableDeclarationStatement
[Visual Basic] <Serializable> <ClassInterface(ClassInterfaceType.AutoDispatch)> <ComVisible(True)> Public Class CodeVariableDeclarationStatement Inherits CodeStatement [C#] [Serializable] [ClassInterface(ClassInterfaceType.AutoDispatch)] [ComVisible(true)] public class CodeVariableDeclarationStatement : CodeStatement [C++] [Serializable] [ClassInterface(ClassInterfaceType::AutoDispatch)] [ComVisible(true)] public __gc class CodeVariableDeclarationStatement : public CodeStatement [JScript] public Serializable ClassInterface(ClassInterfaceType.AutoDispatch) ComVisible(true) class CodeVariableDeclarationStatement extends CodeStatement
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
CodeVariableDeclarationStatement can be used to represent code that declares a variable.
The Type property specifies the type of the variable to declare. The Name property specifies the name of the variable to declare. The InitExpression property is optional, and specifies an initialization expression to assign to the variable after it is created.
Note Some languages can implement the optional variable initialization expression by making a separate assignment statement after the variable declaration.
Example
[Visual Basic, C#, C++] This example demonstrates using a CodeVariableDeclarationStatement to declare a variable.
[Visual Basic] 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" [C#] 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"; [C++] CodeVariableDeclarationStatement* variableDeclaration = new CodeVariableDeclarationStatement( // Type of the variable to declare. __typeof(String), // Name of the variable to declare. S"TestString", // Optional initExpression parameter initializes the variable. new CodePrimitiveExpression(S"Testing") ); // A C# code generator produces the following source code for the preceeding example code: // string TestString = "Testing";
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.CodeDom
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
See Also
CodeVariableDeclarationStatement Members | System.CodeDom Namespace