通过


CodeVariableDeclarationStatement 类

定义

表示变量声明。

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

示例

此示例演示如何使用声明 CodeVariableDeclarationStatement 变量。

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 可用于表示声明变量的代码。

Type 属性指定要声明的变量的类型。 该 Name 属性指定要声明的变量的名称。 该 InitExpression 属性是可选的,并指定要在创建变量后分配给变量的初始化表达式。

注释

某些语言可以通过在变量声明后创建单独的赋值语句来实现可选的变量初始化表达式。

构造函数

名称 说明
CodeVariableDeclarationStatement()

初始化 CodeVariableDeclarationStatement 类的新实例。

CodeVariableDeclarationStatement(CodeTypeReference, String, CodeExpression)

使用指定的数据类型、变量名称和初始化表达式初始化类的新实例 CodeVariableDeclarationStatement

CodeVariableDeclarationStatement(CodeTypeReference, String)

使用指定的类型和名称初始化类的新实例 CodeVariableDeclarationStatement

CodeVariableDeclarationStatement(String, String, CodeExpression)

使用指定的数据类型、变量名称和初始化表达式初始化类的新实例 CodeVariableDeclarationStatement

CodeVariableDeclarationStatement(String, String)

使用指定的数据类型名称和变量名称初始化类的新实例 CodeVariableDeclarationStatement

CodeVariableDeclarationStatement(Type, String, CodeExpression)

使用指定的数据类型、变量名称和初始化表达式初始化类的新实例 CodeVariableDeclarationStatement

CodeVariableDeclarationStatement(Type, String)

使用指定的数据类型和变量名称初始化类的新实例 CodeVariableDeclarationStatement

属性

名称 说明
EndDirectives

CodeDirectiveCollection获取包含结束指令的对象。

(继承自 CodeStatement)
InitExpression

获取或设置变量的初始化表达式。

LinePragma

获取或设置代码语句发生所在的行。

(继承自 CodeStatement)
Name

获取或设置变量的名称。

StartDirectives

CodeDirectiveCollection获取包含 start 指令的对象。

(继承自 CodeStatement)
Type

获取或设置变量的数据类型。

UserData

获取当前对象的用户可定义数据。

(继承自 CodeObject)

方法

名称 说明
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于