CodeVariableDeclarationStatement CodeVariableDeclarationStatement CodeVariableDeclarationStatement CodeVariableDeclarationStatement Class

定義

表示變數宣告。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
繼承
CodeVariableDeclarationStatementCodeVariableDeclarationStatementCodeVariableDeclarationStatementCodeVariableDeclarationStatement
屬性

範例

這個範例示範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() CodeVariableDeclarationStatement() CodeVariableDeclarationStatement()

初始化 CodeVariableDeclarationStatement 類別的新執行個體。Initializes a new instance of the CodeVariableDeclarationStatement class.

CodeVariableDeclarationStatement(CodeTypeReference, String) CodeVariableDeclarationStatement(CodeTypeReference, String) CodeVariableDeclarationStatement(CodeTypeReference, String) CodeVariableDeclarationStatement(CodeTypeReference, String)

使用指定的型別和名稱來初始化 CodeVariableDeclarationStatement 類別的新執行個體。Initializes a new instance of the CodeVariableDeclarationStatement class using the specified type and name.

CodeVariableDeclarationStatement(CodeTypeReference, String, CodeExpression) CodeVariableDeclarationStatement(CodeTypeReference, String, CodeExpression) CodeVariableDeclarationStatement(CodeTypeReference, String, CodeExpression) 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(String, String) CodeVariableDeclarationStatement(String, String) 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(String, String, CodeExpression) CodeVariableDeclarationStatement(String, String, CodeExpression) 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(Type, String) CodeVariableDeclarationStatement(Type, String) 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(Type, String, CodeExpression) CodeVariableDeclarationStatement(Type, String, CodeExpression) CodeVariableDeclarationStatement(Type, String, CodeExpression)

使用指定的資料型別、變數名稱和初始化運算式,初始化 CodeVariableDeclarationStatement 類別的新執行個體。Initializes a new instance of the CodeVariableDeclarationStatement class using the specified data type, variable name, and initialization expression.

屬性

EndDirectives EndDirectives EndDirectives EndDirectives

取得包含結尾指示詞的 CodeDirectiveCollection 物件。Gets a CodeDirectiveCollection object that contains end directives.

(Inherited from CodeStatement)
InitExpression InitExpression InitExpression InitExpression

取得或設定變數的初始化運算式。Gets or sets the initialization expression for the variable.

LinePragma LinePragma LinePragma LinePragma

取得或設定程式碼陳述式發生所在的行。Gets or sets the line on which the code statement occurs.

(Inherited from CodeStatement)
Name Name Name Name

取得或設定變數的名稱。Gets or sets the name of the variable.

StartDirectives StartDirectives StartDirectives StartDirectives

取得包含開頭指示詞的 CodeDirectiveCollection 物件。Gets a CodeDirectiveCollection object that contains start directives.

(Inherited from CodeStatement)
Type Type Type Type

取得或設定變數資料型別。Gets or sets the data type of the variable.

UserData UserData UserData UserData

取得目前物件的使用者可定義資料。Gets the user-definable data for the current object.

(Inherited from CodeObject)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

適用於