CodeVariableDeclarationStatement Class
TOC
Collapse the table of content
Expand the table of content

CodeVariableDeclarationStatement Class

 

Represents a variable declaration.

Namespace:   System.CodeDom
Assembly:  System (in System.dll)

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeStatement
      System.CodeDom.CodeVariableDeclarationStatement

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeVariableDeclarationStatement : CodeStatement

NameDescription
System_CAPS_pubmethodCodeVariableDeclarationStatement()

Initializes a new instance of the CodeVariableDeclarationStatement class.

System_CAPS_pubmethodCodeVariableDeclarationStatement(CodeTypeReference, String)

Initializes a new instance of the CodeVariableDeclarationStatement class using the specified type and name.

System_CAPS_pubmethodCodeVariableDeclarationStatement(CodeTypeReference, String, CodeExpression)

Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type, variable name, and initialization expression.

System_CAPS_pubmethodCodeVariableDeclarationStatement(String, String)

Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type name and variable name.

System_CAPS_pubmethodCodeVariableDeclarationStatement(String, String, CodeExpression)

Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type, variable name, and initialization expression.

System_CAPS_pubmethodCodeVariableDeclarationStatement(Type, String)

Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type and variable name.

System_CAPS_pubmethodCodeVariableDeclarationStatement(Type, String, CodeExpression)

Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type, variable name, and initialization expression.

NameDescription
System_CAPS_pubpropertyEndDirectives

Gets a CodeDirectiveCollection object that contains end directives.(Inherited from CodeStatement.)

System_CAPS_pubpropertyInitExpression

Gets or sets the initialization expression for the variable.

System_CAPS_pubpropertyLinePragma

Gets or sets the line on which the code statement occurs. (Inherited from CodeStatement.)

System_CAPS_pubpropertyName

Gets or sets the name of the variable.

System_CAPS_pubpropertyStartDirectives

Gets a CodeDirectiveCollection object that contains start directives.(Inherited from CodeStatement.)

System_CAPS_pubpropertyType

Gets or sets the data type of the variable.

System_CAPS_pubpropertyUserData

Gets the user-definable data for the current object.(Inherited from CodeObject.)

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

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.

System_CAPS_noteNote

Some languages can implement the optional variable initialization expression by making a separate assignment statement after the variable declaration.

This example demonstrates using a CodeVariableDeclarationStatement to declare a variable.

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";

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft