CodeConditionStatement CodeConditionStatement CodeConditionStatement CodeConditionStatement Class

定義

表示條件分支陳述式 (Statement),通常表示為 if 陳述式。Represents a conditional branch statement, typically represented as an if statement.

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

範例

這個範例示範如何使用CodeConditionStatementif表示具有else區塊的語句。This example demonstrates using a CodeConditionStatement to represent an if statement with an else block.

// 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時要執行的語句集合, 以及條件運算式評估時要執行的選擇性語句集合。至falseCodeConditionStatement can be used to represent code that consists of a conditional expression, a collection of statements to execute if the conditional expression evaluates to true, and an optional collection of statements to execute if the conditional expression evaluates to false. 會以許多語言if產生語句。 CodeConditionStatementA CodeConditionStatement is generated in many languages as an if statement.

Condition屬性會指出要測試的運算式。The Condition property indicates the expression to test. 屬性包含要測試的運算式評估為true時要執行的語句。 TrueStatementsThe TrueStatements property contains the statements to execute if the expression to test evaluates to true. 屬性包含要測試的運算式評估為false時要執行的語句。 FalseStatementsThe FalseStatements property contains the statements to execute if the expression to test evaluates to false.

建構函式

CodeConditionStatement() CodeConditionStatement() CodeConditionStatement() CodeConditionStatement()

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

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

使用指定的條件和陳述式,來初始化 CodeConditionStatement 類別的新執行個體。Initializes a new instance of the CodeConditionStatement class using the specified condition and statements.

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

使用指定的條件和陳述式,來初始化 CodeConditionStatement 類別的新執行個體。Initializes a new instance of the CodeConditionStatement class using the specified condition and statements.

屬性

Condition Condition Condition Condition

取得或設定運算式以評估 truefalseGets or sets the expression to evaluate true or false.

EndDirectives EndDirectives EndDirectives EndDirectives

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

(Inherited from CodeStatement)
FalseStatements FalseStatements FalseStatements FalseStatements

如果條件運算式判定為 false,則取得要執行的陳述式的集合。Gets the collection of statements to execute if the conditional expression evaluates to false.

LinePragma LinePragma LinePragma LinePragma

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

(Inherited from CodeStatement)
StartDirectives StartDirectives StartDirectives StartDirectives

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

(Inherited from CodeStatement)
TrueStatements TrueStatements TrueStatements TrueStatements

如果條件運算式判定為 true,則取得要執行的陳述式的集合。Gets the collection of statements to execute if the conditional expression evaluates to true.

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)

適用於