Expression.And 方法

定義

建立表示位元 BinaryExpression 運算的 AND

多載

And(Expression, Expression)

建立表示位元 BinaryExpression 運算的 AND

And(Expression, Expression, MethodInfo)

建立表示位元 BinaryExpression 運算的 AND。 實作的方法可加以指定。

And(Expression, Expression)

來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs

建立表示位元 BinaryExpression 運算的 AND

public:
 static System::Linq::Expressions::BinaryExpression ^ And(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right);
public static System.Linq.Expressions.BinaryExpression And (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right);
static member And : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.BinaryExpression
Public Shared Function And (left As Expression, right As Expression) As BinaryExpression

參數

left
Expression

要將 Expression 屬性設定為與之相等的 Left

right
Expression

要將 Expression 屬性設定為與之相等的 Right

傳回

BinaryExpression,其 NodeType 屬性等於 And,且 LeftRight 屬性設定為指定的值。

例外狀況

leftrightnull

不會為 left.Type 和 right.Type 定義位元 AND 運算子。

範例

下列程式代碼範例示範如何建立表達式,代表兩個布爾值的邏輯AND運算。

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

// This expression perfroms a logical AND operation
// on its two arguments. Both arguments must be of the same type,
// which can be boolean or integer.
Expression andExpr = Expression.And(
    Expression.Constant(true),
    Expression.Constant(false)
);

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

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

// This code example produces the following output:
//
// (True And False)
// False
' Add the following directive to your file:
' Imports System.Linq.Expressions 

' This expression performs a logical AND operation
' on its two arguments. Both arguments must be of the same type,
' which can be Boolean or integer.             
Dim andExpr As Expression = Expression.And(
    Expression.Constant(True),
    Expression.Constant(False)
    )

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

' The following statement first creates an expression tree,
' then compiles it, and then executes it.       
Console.WriteLine(
    Expression.Lambda(Of Func(Of Boolean))(andExpr).Compile()())
' This code example produces the following output:
'
' (True And False)
' False

備註

產生的 BinaryExpressionMethod 屬性已設定為實作方法。 屬性 Type 會設定為節點的類型。 如果隨即解除節點, IsLiftedIsLiftedToNull 屬性都是 true。 否則,它們是 falseConversion 屬性為 null

下列資訊描述實作方法、節點類型,以及節點是否已增益。

實作方法

下列規則會決定作業的實作方法:

  • Type如果 或 rightleft 屬性代表多載位AND運算子的使用者定義型別,MethodInfo則表示該方法的 是實作方法。

  • 否則,如果 left為 。輸入與 right。類型是整數或布爾型別,實作方法是 null

節點類型和隨即轉移與非隨即轉移的比較

如果實作方法不是 null

  • 如果為 left。輸入與 right。類型可指派給實作方法的對應自變數類型,節點不會隨即解除。 節點的類型是實作方法的傳回型別。

  • 如果滿足下列兩個條件,則會隨即解除節點,而節點的類型是對應至實作方法之傳回型別的可為 Null 型別:

    • left.輸入與 right。類型是兩種實值型別,其中至少有一個可為 Null,而對應的不可為 Null 型別等於實作方法的對應自變數類型。

    • 實作方法的傳回型別是不可為 Null 的實值型別。

如果實作方法為 null

  • 如果為 left。輸入與 right。類型都是不可為 Null 的,節點不會隨即解除。 節點的類型是預先定義之位 AND 運算子的結果類型。

  • 如果為 left。輸入與 right。類型都是可為 Null 的,節點會隨即隨即解除。 節點的類型是對應至預先定義位 AND 運算子之結果型別的可為 Null 型別。

適用於

And(Expression, Expression, MethodInfo)

來源:
BinaryExpression.cs
來源:
BinaryExpression.cs
來源:
BinaryExpression.cs

建立表示位元 BinaryExpression 運算的 AND。 實作的方法可加以指定。

public:
 static System::Linq::Expressions::BinaryExpression ^ And(System::Linq::Expressions::Expression ^ left, System::Linq::Expressions::Expression ^ right, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.BinaryExpression And (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.BinaryExpression And (System.Linq.Expressions.Expression left, System.Linq.Expressions.Expression right, System.Reflection.MethodInfo? method);
static member And : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.BinaryExpression
Public Shared Function And (left As Expression, right As Expression, method As MethodInfo) As BinaryExpression

參數

left
Expression

要將 Expression 屬性設定為與之相等的 Left

right
Expression

要將 Expression 屬性設定為與之相等的 Right

method
MethodInfo

要將 MethodInfo 屬性設定為與之相等的 Method

傳回

BinaryExpression,其 NodeType 屬性等於 And,且 LeftRightMethod 屬性設定為指定的值。

例外狀況

leftrightnull

method 不是 null,而它所代表的方法會傳回 void、不是 static (Visual Basic 中的 Shared),或者未確切採用兩個引數。

methodnull,而且未定義 left.Type 和 right.Type 的位元 AND 運算子。

備註

產生的 BinaryExpressionMethod 屬性已設定為實作方法。 屬性 Type 會設定為節點的類型。 如果隨即解除節點, IsLiftedIsLiftedToNull 屬性都是 true。 否則,它們是 falseConversion 屬性為 null

下列資訊描述實作方法、節點類型,以及節點是否已增益。

實作方法

會根據下列規則來選擇作業的實作方法:

  • 如果 method 不是 null 且它代表非 void, static (Shared Visual Basic) 方法中採用兩個自變數,則它是節點的實作方法。

  • 否則,如果 Typerightleft 屬性表示多載位AND運算子的使用者定義型別,MethodInfo則表示該方法的 是實作方法。

  • 否則,如果 left為 。輸入與 right。類型是整數或布爾型別,實作方法是 null

節點類型和隨即轉移與非隨即轉移的比較

如果實作方法不是 null

  • 如果為 left。輸入與 right。類型可指派給實作方法的對應自變數類型,節點不會隨即解除。 節點的類型是實作方法的傳回型別。

  • 如果滿足下列兩個條件,則會隨即解除節點,而節點的類型是對應至實作方法之傳回型別的可為 Null 型別:

    • left.輸入與 right。類型是兩種實值型別,其中至少有一個可為 Null,而對應的不可為 Null 型別等於實作方法的對應自變數類型。

    • 實作方法的傳回型別是不可為 Null 的實值型別。

如果實作方法為 null

  • 如果為 left。輸入與 right。類型都是不可為 Null 的,節點不會隨即解除。 節點的類型是預先定義之位 AND 運算子的結果類型。

  • 如果為 left。輸入與 right。類型都是可為 Null 的,節點會隨即隨即解除。 節點的類型是對應至預先定義位 AND 運算子之結果型別的可為 Null 型別。

適用於