CodeVariableDeclarationStatement 类

定义

表示变量声明。Represents a variable declaration.

public ref class CodeVariableDeclarationStatement : System::CodeDom::CodeStatement
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeVariableDeclarationStatement : System.CodeDom.CodeStatement
type CodeVariableDeclarationStatement = class
    inherit CodeStatement
Public Class CodeVariableDeclarationStatement
Inherits CodeStatement
继承
CodeVariableDeclarationStatement
属性

示例

此示例演示CodeVariableDeclarationStatement如何使用来声明变量。This example demonstrates using a CodeVariableDeclarationStatement to declare a variable.

// 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.
    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";
 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可用于表示声明变量的代码。CodeVariableDeclarationStatement can be used to represent code that declares a variable.

Type属性指定要声明的变量的类型。The Type property specifies the type of the variable to declare. Name属性指定要声明的变量的名称。The Name property specifies the name of the variable to declare. 属性InitExpression是可选的, 它指定在创建变量后要分配给该变量的初始化表达式。The InitExpression property is optional, and specifies an initialization expression to assign to the variable after it is created.

备注

某些语言可以通过在变量声明后创建一个单独的赋值语句来实现可选的变量初始化表达式。Some languages can implement the optional variable initialization expression by making a separate assignment statement after the variable declaration.

构造函数

CodeVariableDeclarationStatement()

初始化 CodeVariableDeclarationStatement 类的新实例。Initializes a new instance of the CodeVariableDeclarationStatement class.

CodeVariableDeclarationStatement(CodeTypeReference, String)

使用指定的类型和名称初始化 CodeVariableDeclarationStatement 类的新实例。Initializes a new instance of the CodeVariableDeclarationStatement class using the specified type and name.

CodeVariableDeclarationStatement(CodeTypeReference, String, CodeExpression)

使用指定的数据类型、变量名和初始化表达式初始化 CodeVariableDeclarationStatement 类的新实例。Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type, variable name, and initialization expression.

CodeVariableDeclarationStatement(String, String)

使用指定的数据类型名称和变量名初始化 CodeVariableDeclarationStatement 类的新实例。Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type name and variable name.

CodeVariableDeclarationStatement(String, String, CodeExpression)

使用指定的数据类型、变量名和初始化表达式初始化 CodeVariableDeclarationStatement 类的新实例。Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type, variable name, and initialization expression.

CodeVariableDeclarationStatement(Type, String)

使用指定的数据类型和变量名初始化 CodeVariableDeclarationStatement 类的新实例。Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type and variable name.

CodeVariableDeclarationStatement(Type, String, CodeExpression)

使用指定的数据类型、变量名和初始化表达式初始化 CodeVariableDeclarationStatement 类的新实例。Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type, variable name, and initialization expression.

属性

EndDirectives

获取包含结束指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains end directives.

(继承自 CodeStatement)
InitExpression

获取或设置变量的初始化表达式。Gets or sets the initialization expression for the variable.

LinePragma

获取或设置代码语句所在的行。Gets or sets the line on which the code statement occurs.

(继承自 CodeStatement)
Name

获取或设置变量名。Gets or sets the name of the variable.

StartDirectives

获取包含开始指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains start directives.

(继承自 CodeStatement)
Type

获取或设置变量的数据类型。Gets or sets the data type of the variable.

UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于