CodeConditionStatement 類別
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示條件分支陳述式 (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 來表示具有 區塊的 if
else
語句。
// 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會包含要執行的語句。
Code |
初始化 CodeConditionStatement 類別的新執行個體。 |
Code |
使用指定的條件和陳述式,來初始化 CodeConditionStatement 類別的新執行個體。 |
Code |
使用指定的條件和陳述式,來初始化 CodeConditionStatement 類別的新執行個體。 |
Condition |
取得或設定運算式以評估 |
End |
取得包含結尾指示詞的 CodeDirectiveCollection 物件。 (繼承來源 CodeStatement) |
False |
如果條件運算式判定為 |
Line |
取得或設定程式碼陳述式發生所在的行。 (繼承來源 CodeStatement) |
Start |
取得包含開頭指示詞的 CodeDirectiveCollection 物件。 (繼承來源 CodeStatement) |
True |
如果條件運算式判定為 |
User |
取得目前物件的使用者可定義資料。 (繼承來源 CodeObject) |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Get |
做為預設雜湊函式。 (繼承來源 Object) |
Get |
取得目前執行個體的 Type。 (繼承來源 Object) |
Memberwise |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
To |
傳回代表目前物件的字串。 (繼承來源 Object) |
產品 | 版本 |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |