Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Stellt eine bedingte Verzweigungsanweisung dar, die i. d. R. als if-Anweisung dargestellt wird.
Namespace: System.CodeDom
Assembly: System (in system.dll)
Syntax
'Declaration
<SerializableAttribute> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
Public Class CodeConditionStatement
Inherits CodeStatement
'Usage
Dim instance As CodeConditionStatement
[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
public class CodeConditionStatement : CodeStatement
[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
public ref class CodeConditionStatement : public CodeStatement
/** @attribute SerializableAttribute() */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */
/** @attribute ComVisibleAttribute(true) */
public class CodeConditionStatement extends CodeStatement
SerializableAttribute
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)
ComVisibleAttribute(true)
public class CodeConditionStatement extends CodeStatement
Hinweise
Mit CodeConditionStatement kann Code dargestellt werden, der aus folgenden Elementen besteht: einem bedingten Ausdruck, einer Auflistung von Ausdrücken, die bei einer Auswertung des bedingten Ausdrucks mit true ausgeführt werden sollen, sowie einer optionalen Auflistung von Ausdrücken, die bei einer Auswertung des bedingten Ausdrucks mit false ausgeführt werden sollen. Ein CodeConditionStatement wird in vielen Sprachen als if-Anweisung generiert.
Die Condition-Eigenschaft gibt den zu testenden Ausdruck an. Die TrueStatements-Eigenschaft enthält die Anweisungen, die ausgeführt werden sollen, wenn der zu testende Ausdruck true ergibt. Die FalseStatements-Eigenschaft enthält die Anweisungen, die ausgeführt werden sollen, wenn der zu testende Ausdruck false ergibt.
Beispiel
In diesem Beispiel wird veranschaulicht, wie mit einem CodeConditionStatement eine if-Anweisung mit einem else-Block dargestellt wird.
' 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.
// 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.
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 VJ# 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.
// }
Vererbungshierarchie
System.Object
System.CodeDom.CodeObject
System.CodeDom.CodeStatement
System.CodeDom.CodeConditionStatement
Threadsicherheit
Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.
Plattformen
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0