CodeConditionStatement 類別

定義

表示條件分支陳述式 (Statement),通常表示為 if 陳述式。

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

範例

此範例示範如何使用 CodeConditionStatement 來表示具有 區塊的 ifelse 語句。

// Create a CodeConditionStatement that tests a boolean value named boolean.
array<CodeStatement^>^temp0 = {gcnew CodeCommentStatement( "If condition is true, execute these statements." )};
array<CodeStatement^>^temp1 = {gcnew CodeCommentStatement( "Else block. If condition is false, execute these statements." )};

// The statements to execute if the condition evalues to false.
CodeConditionStatement^ conditionalStatement = gcnew CodeConditionStatement( gcnew CodeVariableReferenceExpression( "boolean" ),temp0,temp1 );

// A C# code generator produces the following source code for the preceeding example code:
// if (boolean) 
// {
//     // If condition is true, execute these statements.
// }
// else {
//     // Else block. If condition is false, execute these statements.
// }
// Create a CodeConditionStatement that tests a boolean value named boolean.
CodeConditionStatement conditionalStatement = new CodeConditionStatement(
    // The condition to test.
    new CodeVariableReferenceExpression("boolean"),
    // The statements to execute if the condition evaluates to true.
    new CodeStatement[] { new CodeCommentStatement("If condition is true, execute these statements.") },
    // The statements to execute if the condition evalues to false.
    new CodeStatement[] { new CodeCommentStatement("Else block. If condition is false, execute these statements.") } );

// A C# code generator produces the following source code for the preceeding example code:

// if (boolean)
// {
    //     // If condition is true, execute these statements.
// }
// else {
//     // Else block. If condition is false, execute these statements.
    // }
' Create a CodeConditionStatement that tests a boolean value named boolean.
 Dim conditionalStatement As New CodeConditionStatement( _
      New CodeVariableReferenceExpression("boolean"), _
      New CodeStatement() {New CodeCommentStatement("If condition is true, execute these statements.")}, _
      New CodeStatement() {New CodeCommentStatement("Else block. If condition is false, execute these statements.")})

' A Visual Basic code generator produces the following source code for the preceeding example code:

' If [boolean] Then
'     'If condition is true, execute these statements.
' Else
'     'Else block. If condition is false, execute these statements.

備註

CodeConditionStatement 可以用來表示由條件表達式組成的程式代碼、條件表示式評估為 true時要執行的語句集合,以及條件表達式評估為 false時要執行的選擇性語句集合。 會 CodeConditionStatement 以許多語言產生 作為 if 語句。

屬性 Condition 會指出要測試的表達式。 如果要測試的表達式評估為 true,屬性TrueStatements會包含要執行的語句。 如果要測試的表達式評估為 false,屬性FalseStatements會包含要執行的語句。

建構函式

CodeConditionStatement()

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

CodeConditionStatement(CodeExpression, CodeStatement[])

使用指定的條件和陳述式,來初始化 CodeConditionStatement 類別的新執行個體。

CodeConditionStatement(CodeExpression, CodeStatement[], CodeStatement[])

使用指定的條件和陳述式,來初始化 CodeConditionStatement 類別的新執行個體。

屬性

Condition

取得或設定運算式以評估 truefalse

EndDirectives

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

(繼承來源 CodeStatement)
FalseStatements

如果條件運算式判定為 false,則取得要執行的陳述式的集合。

LinePragma

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

(繼承來源 CodeStatement)
StartDirectives

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

(繼承來源 CodeStatement)
TrueStatements

如果條件運算式判定為 true,則取得要執行的陳述式的集合。

UserData

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

(繼承來源 CodeObject)

方法

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

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

(繼承來源 Object)

適用於