Expression.Condition Yöntem

Tanım

Koşullu deyimi ConditionalExpression temsil eden bir oluşturur.

Aşırı Yüklemeler

Condition(Expression, Expression, Expression)

Koşullu deyimi ConditionalExpression temsil eden bir oluşturur.

Condition(Expression, Expression, Expression, Type)

Koşullu deyimi ConditionalExpression temsil eden bir oluşturur.

Condition(Expression, Expression, Expression)

Kaynak:
ConditionalExpression.cs
Kaynak:
ConditionalExpression.cs
Kaynak:
ConditionalExpression.cs

Koşullu deyimi ConditionalExpression temsil eden bir oluşturur.

public:
 static System::Linq::Expressions::ConditionalExpression ^ Condition(System::Linq::Expressions::Expression ^ test, System::Linq::Expressions::Expression ^ ifTrue, System::Linq::Expressions::Expression ^ ifFalse);
public static System.Linq.Expressions.ConditionalExpression Condition (System.Linq.Expressions.Expression test, System.Linq.Expressions.Expression ifTrue, System.Linq.Expressions.Expression ifFalse);
static member Condition : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.ConditionalExpression
Public Shared Function Condition (test As Expression, ifTrue As Expression, ifFalse As Expression) As ConditionalExpression

Parametreler

test
Expression

Expression özelliğinin Test değerine eşit olarak ayarlanması için.

ifTrue
Expression

Expression özelliğinin IfTrue değerine eşit olarak ayarlanması için.

ifFalse
Expression

Expression özelliğinin IfFalse değerine eşit olarak ayarlanması için.

Döndürülenler

ConditionalExpression özelliğine ConditionalNodeType eşit olan ve Test, IfTrueve IfFalse özellikleri belirtilen değerlere ayarlanmış.

Özel durumlar

test veya ifTrue veya ifFalse şeklindedir null.

test. Tür değil Boolean.

-veya-

ifTrue. Tür ile ifFalseeşit değildir. Türü.

Örnekler

Aşağıdaki kod örneği, koşullu deyimi temsil eden bir ifadenin nasıl oluşturulacağını gösterir. İlk bağımsız değişken olarak değerlendirilirse trueikinci bağımsız değişken yürütülür; aksi takdirde üçüncü bağımsız değişken yürütülür.

// Add the following directive to your file:
// using System.Linq.Expressions;

int num = 100;

// This expression represents a conditional operation.
// It evaluates the test (first expression) and
// executes the iftrue block (second argument) if the test evaluates to true,
// or the iffalse block (third argument) if the test evaluates to false.
Expression conditionExpr = Expression.Condition(
                           Expression.Constant(num > 10),
                           Expression.Constant("num is greater than 10"),
                           Expression.Constant("num is smaller than 10")
                         );

// Print out the expression.
Console.WriteLine(conditionExpr.ToString());

// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(
    Expression.Lambda<Func<string>>(conditionExpr).Compile()());

// This code example produces the following output:
//
// IIF("True", "num is greater than 10", "num is smaller than 10")
// num is greater than 10
' Add the following directive to your file:
' Imports System.Linq.Expressions  

Dim num As Integer = 100

' This expression represents a conditional operation; 
' it will evaluate the test (first expression) and
' execute the ifTrue block (second argument) if the test evaluates to true, 
' or the ifFalse block (third argument) if the test evaluates to false.
Dim conditionExpr As Expression = Expression.Condition(
                            Expression.Constant(num > 10),
                            Expression.Constant("n is greater than 10"),
                            Expression.Constant("n is smaller than 10")
                        )

' Print the expression.
Console.WriteLine(conditionExpr.ToString())

' The following statement first creates an expression tree,
' then compiles it, and then executes it.       
Console.WriteLine(
    Expression.Lambda(Of Func(Of String))(conditionExpr).Compile()())

' This code example produces the following output:
'
' IIF("True", "num is greater than 10", "num is smaller than 10")
' num is greater than 10

Açıklamalar

Sonuçta TypeConditionalExpression elde edilen özelliği özelliğine TypeifTrueeşittir.

Ayrıca bkz.

Şunlara uygulanır

Condition(Expression, Expression, Expression, Type)

Kaynak:
ConditionalExpression.cs
Kaynak:
ConditionalExpression.cs
Kaynak:
ConditionalExpression.cs

Koşullu deyimi ConditionalExpression temsil eden bir oluşturur.

public:
 static System::Linq::Expressions::ConditionalExpression ^ Condition(System::Linq::Expressions::Expression ^ test, System::Linq::Expressions::Expression ^ ifTrue, System::Linq::Expressions::Expression ^ ifFalse, Type ^ type);
public static System.Linq.Expressions.ConditionalExpression Condition (System.Linq.Expressions.Expression test, System.Linq.Expressions.Expression ifTrue, System.Linq.Expressions.Expression ifFalse, Type type);
static member Condition : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * Type -> System.Linq.Expressions.ConditionalExpression
Public Shared Function Condition (test As Expression, ifTrue As Expression, ifFalse As Expression, type As Type) As ConditionalExpression

Parametreler

test
Expression

Expression özelliğinin Test değerine eşit olarak ayarlanması için.

ifTrue
Expression

Expression özelliğinin IfTrue değerine eşit olarak ayarlanması için.

ifFalse
Expression

Expression özelliğinin IfFalse değerine eşit olarak ayarlanması için.

type
Type

Özelliğinin Type değerine eşit olarak ayarlanması için AType.

Döndürülenler

ConditionalExpression özelliğine ConditionalNodeType eşit olan ve Test, IfTrueve IfFalse özellikleri belirtilen değerlere ayarlanmış.

Açıklamalar

Bu yöntem, ve ifFalse ifadelerinin türlerinin eşit olmadığı durumlarda koşullu ifadenin sonuç türünü ifTrue açıkça birleştirmeye olanak tanır. Hem hem de ifTrueifFalse türleri, sonuç türüne atanabilir örtük olarak başvurulmalıdır. öğesinin type olması Voidiçin izin verilir.

Şunlara uygulanır