Share via


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 來宣告變數。

// 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 可以用來表示宣告變數的程序代碼。

屬性 Type 會指定要宣告的變數類型。 屬性 Name 會指定要宣告的變數名稱。 屬性 InitExpression 是選擇性的,並指定要在建立變數之後指派給變數的初始化表達式。

注意

有些語言可以在變數宣告之後建立個別的指派語句,以實作選擇性變數初始化表達式。

建構函式

CodeVariableDeclarationStatement()

初始化 CodeVariableDeclarationStatement 類別的新執行個體。

CodeVariableDeclarationStatement(CodeTypeReference, String)

使用指定的型別和名稱來初始化 CodeVariableDeclarationStatement 類別的新執行個體。

CodeVariableDeclarationStatement(CodeTypeReference, String, CodeExpression)

使用指定的資料型別、變數名稱和初始化運算式,初始化 CodeVariableDeclarationStatement 類別的新執行個體。

CodeVariableDeclarationStatement(String, String)

使用指定的資料型別名稱和變數名稱來初始化 CodeVariableDeclarationStatement 類別的新執行個體。

CodeVariableDeclarationStatement(String, String, CodeExpression)

使用指定的資料型別、變數名稱和初始化運算式,初始化 CodeVariableDeclarationStatement 類別的新執行個體。

CodeVariableDeclarationStatement(Type, String)

使用指定的資料型別和變數名稱來初始化 CodeVariableDeclarationStatement 類別的新執行個體。

CodeVariableDeclarationStatement(Type, String, CodeExpression)

使用指定的資料型別、變數名稱和初始化運算式,初始化 CodeVariableDeclarationStatement 類別的新執行個體。

屬性

EndDirectives

取得包含結尾指示詞的 CodeDirectiveCollection 物件。

(繼承來源 CodeStatement)
InitExpression

取得或設定變數的初始化運算式。

LinePragma

取得或設定程式碼陳述式發生所在的行。

(繼承來源 CodeStatement)
Name

取得或設定變數的名稱。

StartDirectives

取得包含開頭指示詞的 CodeDirectiveCollection 物件。

(繼承來源 CodeStatement)
Type

取得或設定變數的資料類型。

UserData

取得目前物件的使用者可定義資料。

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於