語言

Expression.ExclusiveOr 方法

定義

會產生 BinaryExpression 一個代表位元運算 XOR 的 a。

多載

名稱 Description
ExclusiveOr(Expression, Expression, MethodInfo)

建立 BinaryExpression 一個代表位元 XOR 運算的 ,使用 op_ExclusiveOr 使用者定義型別。 可指定實作方法。

ExclusiveOr(Expression, Expression)

建立 BinaryExpression 一個代表位元 XOR 運算的 ,使用 op_ExclusiveOr 使用者定義型別。

ExclusiveOr(Expression, Expression, MethodInfo)

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

建立 BinaryExpression 一個代表位元 XOR 運算的 ,使用 op_ExclusiveOr 使用者定義型別。 可指定實作方法。

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

參數

left
Expression

Expression A 將屬性Left設為 。

right
Expression

Expression A 將屬性Right設為 。

method
MethodInfo

MethodInfo A 將屬性設Method為 。

傳回

BinaryExpression A 的屬性等NodeType於 ExclusiveOr ,且Left屬性為 ,RightMethod屬性設定為指定的值。

例外狀況

left 或 right 為 null。

method不是null,且它所代表的方法回傳 void, 是 (在 staticShared Visual Basic 中),或不恰好接受兩個參數。

method 是 null ,且 XOR 算符對 不定義。 left類型與 right。打字。

備註

結果 BinaryExpression 中,該屬性設定 Method 為實作方法。 屬性 Type 會設定為節點的類型。 如果節點被取消,IsLifted 和 IsLiftedToNull 屬性都是 true。 否則,它們是 false。 IsEditable 屬性為 true。

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

實作方法

以下規則決定了操作所選的實作方法:

  • 如果method不是null,且它代表一個非空staticShared(Visual Basic 中)且接受兩個參數的方法,則它是實作方法。

  • 否則,若 Type 的leftright屬性代表使用者定義的型別,該型別會超載運算XOR子,則MethodInfo該方法的 即為實作方法。

  • 否則,若 left。類型與 right。類型是整數型或布林型,實作方法是 null。

節點類型與提升與非提升

如果實作方法不是 null:

  • 如果 left.型別和 right.型別可以指派給實作方法的對應參數型別,則節點不會被解除。 節點的類型是實作方法的傳回型別。

  • 如果符合下列兩個條件,則節點會提升,並且該節點的類型是對應至實作方法傳回型別的可空類型:

    • left.型別 與 right.型別 都是實值型別,其中至少一個可為 Null,而對應的不可為 Null 型別等於實作方法的對應參數類型。

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

如果實作方法為 null:

  • 如果left.類型與right.類型都是不可為 Null 的,節點不會被提升。 節點的類型是預設 XOR 運算子的結果類型。

  • 如果 left.Type 和 right.Type 都是可為 null 的,則該節點會提升。 節點的型別是可空的型別,對應於預設運算 XOR 子的結果型態。

適用於

ExclusiveOr(Expression, Expression)

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

建立 BinaryExpression 一個代表位元 XOR 運算的 ,使用 op_ExclusiveOr 使用者定義型別。

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

參數

left
Expression

Expression A 將屬性Left設為 。

right
Expression

Expression A 將屬性Right設為 。

傳回

BinaryExpression一個屬性等NodeType於 ,ExclusiveOr且 Left 和 Right 屬性設定為指定值的 a。

例外狀況

left 或 right 為 null。

XOR算符對 未定義。left類型與right。打字。

範例

以下程式碼範例展示了如何建立一個表示邏輯 XOR 運算的表達式。

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

// This expression represents an exclusive OR operation for its two arguments.
// Both arguments must be of the same type,
// which can be either integer or boolean.

Expression exclusiveOrExpr = Expression.ExclusiveOr(
    Expression.Constant(5),
    Expression.Constant(3)
);

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

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

// The XOR operation is performed as follows:
// 101 xor 011 = 110

// This code example produces the following output:
//
// (5 ^ 3)
// 6
' Add the following directive to your file:
' Imports System.Linq.Expressions   

' This expression represents an exclusive OR operation for its two arguments.
' Both arguments must be of the same type, 
' which can be either integer or Boolean.

Dim exclusiveOrExpr As Expression = Expression.ExclusiveOr(
     Expression.Constant(5),
     Expression.Constant(3)
 )

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

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

' The XOR operation is performed as follows:
' 101 xor 011 = 110

' This code example produces the following output:
'
' (5 ^ 3)
' 6

備註

結果 BinaryExpression 中,該屬性設定 Method 為實作方法。 屬性 Type 會設定為節點的類型。 如果節點被取消,IsLifted 和 IsLiftedToNull 屬性都是 true。 否則,它們是 false。 IsEditable 屬性為 true。

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

實作方法

以下規則決定了操作的實作方法:

  • 若 Type 或 left 的right屬性代表使用者定義的型別,且會使運算子超載,XOR則 代表該方法的 就是MethodInfo實作方法。

  • 否則,若 left。類型與 right。類型是整數型或布林型,實作方法是 null。

節點類型與提升與非提升

如果實作方法不是 null:

  • 如果 left.型別和 right.型別可以指派給實作方法的對應參數型別,則節點不會被解除。 節點的類型是實作方法的傳回型別。

  • 如果符合下列兩個條件,則節點會提升,並且該節點的類型是對應至實作方法傳回型別的可空類型:

    • left.型別 與 right.型別 都是實值型別,其中至少一個可為 Null,而對應的不可為 Null 型別等於實作方法的對應參數類型。

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

如果實作方法為 null:

  • 如果left.類型與right.類型都是不可為 Null 的,節點不會被提升。 節點的類型是預設 XOR 運算子的結果類型。

  • 如果 left.Type 和 right.Type 都是可為 null 的,則該節點會提升。 節點的型別是可空的型別,對應於預設運算 XOR 子的結果型態。

適用於