# Expression.OrElse 方法

## 多載

 OrElse(Expression, Expression) 建立 BinaryExpression，表示只在第一個運算元計算結果為 `OR` 時才求第二個運算元之值的 `false` 條件運算。Creates a BinaryExpression that represents a conditional `OR` operation that evaluates the second operand only if the first operand evaluates to `false`. OrElse(Expression, Expression, MethodInfo) 建立 BinaryExpression，表示只在第一個運算元計算結果為 `OR` 時才求第二個運算元之值的 `false` 條件運算。Creates a BinaryExpression that represents a conditional `OR` operation that evaluates the second operand only if the first operand evaluates to `false`.

## OrElse(Expression, Expression)

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

left
Expression

right
Expression

#### 傳回

BinaryExpression

BinaryExpression，其 NodeType 屬性等於 OrElse，且 LeftRight 屬性設定為指定的值。A BinaryExpression that has the NodeType property equal to OrElse and the Left and Right properties set to the specified values.

#### 例外狀況

`left``right``null``left` or `right` is `null`.

-或--or- `left`.Type 和 `right`.Type 是不相同的布林類型。`left`.Type and `right`.Type are not the same Boolean type.

### 範例

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

// This expression perfroms a logical OR operation
// on its two arguments, but if the first argument is true,
// then the second arument is not evaluated.
// Both arguments must be of the boolean type.
Expression orElseExpr = Expression.OrElse(
Expression.Constant(false),
Expression.Constant(true)
);

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

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

// This code example produces the following output:
//
// (False OrElse True)
// True

``````
``````' Add the following directive to your file:
' Imports System.Linq.Expressions

' This expression perfroms a logical OR operation
' on its two arguments, but if the first argument is true,
' the second arument is not evaluated.
' Both arguments must be of the Boolean type.
Dim orElseExpr As Expression = Expression.OrElse(
Expression.Constant(False),
Expression.Constant(True)
)

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

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

' This code example produces the following output:
'
' (False OrElse True)
' True

``````

### 備註

#### 實方法Implementing Method

• 如果 Type 或的屬性代表多載 `left` `right` 位運算子的使用者定義型別 `OR`MethodInfo 表示該方法的會是實方法。If the Type property of either `left` or `right` represents a user-defined type that overloads the bitwise `OR` operator, the MethodInfo that represents that method is the implementing method.

注意

條件 `OR` 運算子無法在 c # 或 Visual Basic 中多載。The conditional `OR` operator cannot be overloaded in C# or Visual Basic. 不過，條件 `OR` 運算子是使用位運算子來評估 `OR`However, the conditional `OR` operator is evaluated by using the bitwise `OR` operator. 因此，位運算子的使用者定義多載 `OR` 可以是此節點類型的實方法。Thus, a user-defined overload of the bitwise `OR` operator can be the implementing method for this node type.

• 否則為 `left` 。輸入和 `right` 。類型是布林值類型，實方法是 `null`Otherwise, if `left`.Type and `right`.Type are Boolean types, the implementing method is `null`.

#### 節點類型和提升與未提升Node Type and Lifted versus Non-Lifted

• 如果為，則為 `left` 。輸入和 `right` 。類型可指派給實方法的對應引數類型，而不會引發節點。If `left`.Type and `right`.Type are assignable to the corresponding argument types of the implementing method, the node is not lifted. 節點的型別是實方法的傳回型別。The type of the node is the return type of the implementing method.

• 如果符合下列兩個條件，節點就會被提升，而節點的類型會是可為 null 的型別，該型別會對應至實方法的傳回型別：If the following two conditions are satisfied, the node is lifted and the type of the node is the nullable type that corresponds to the return type of the implementing method:

• `left`.輸入和 `right` 。類型是至少一個可為 null 的實值型別，而對應的不可為 null 的型別等於實方法的對應引數類型。`left`.Type and `right`.Type are both value types of which at least one is nullable, and the corresponding non-nullable types are equal to the corresponding argument types of the implementing method.

• 實方法的傳回型別是不可為 null 的實值型別。The return type of the implementing method is a non-nullable value type.

• `left`.輸入和 `right` 。類型是相同的布林類型。`left`.Type and `right`.Type are the same Boolean type.

• 如果為，則為 `left` 。輸入和 `right` 。類型不可為 null，節點不會被提升。If `left`.Type and `right`.Type are non-nullable, the node is not lifted. 節點的型別是預先定義之條件運算子的結果型別 `OR`The type of the node is the result type of the predefined conditional `OR` operator.

• 如果為，則為 `left` 。輸入和 `right` 。型別可為 null，節點會被提升。If `left`.Type and `right`.Type are nullable, the node is lifted. 節點的型別是可為 null 的型別，它會對應到預先定義之條件運算子的結果型別 `OR`The type of the node is the nullable type that corresponds to the result type of the predefined conditional `OR` operator.

## OrElse(Expression, Expression, MethodInfo)

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

left
Expression

right
Expression

method
MethodInfo

#### 傳回

BinaryExpression

BinaryExpression，其 NodeType 屬性等於 OrElse，且 LeftRightMethod 屬性設定為指定的值。A BinaryExpression that has the NodeType property equal to OrElse and the Left, Right, and Method properties set to the specified values.

#### 例外狀況

`left``right``null``left` or `right` is `null`.

`method` 不是 `null`，而它所代表的方法會傳回 `void`、不是 `static` (Visual Basic 中的 `Shared`)，或者未確切採用兩個引數。`method` is not `null` and the method it represents returns `void`, is not `static` (`Shared` in Visual Basic), or does not take exactly two arguments.

`method``null`，而且未定義 `left`.Type 和 `right`.Type 的位元 `OR` 運算子。`method` is `null` and the bitwise `OR` operator is not defined for `left`.Type and `right`.Type.

-或--or- `method``null`，且 `left`.Type 和 `right`.Type 不是相同的布林類型。`method` is `null` and `left`.Type and `right`.Type are not the same Boolean type.

### 備註

#### 實方法Implementing Method

• 如果不 `method` 是， `null` 而它代表非 void，則 `static` `Shared` 在採用兩個引數的 Visual Basic) 方法中 (，它就是節點的實作為方法。If `method` is not `null` and it represents a non-void, `static` (`Shared` in Visual Basic) method that takes two arguments, it is the implementing method for the node.

• 否則，如果 Type 或的屬性代表多載 `left` `right` 位運算子的使用者定義型別 `OR`MethodInfo 表示該方法的會是實方法。Otherwise, if the Type property of either `left` or `right` represents a user-defined type that overloads the bitwise `OR` operator, the MethodInfo that represents that method is the implementing method.

注意

條件 `OR` 運算子無法在 c # 或 Visual Basic 中多載。The conditional `OR` operator cannot be overloaded in C# or Visual Basic. 不過，條件 `OR` 運算子是使用位運算子來評估 `OR`However, the conditional `OR` operator is evaluated by using the bitwise `OR` operator. 因此，位運算子的使用者定義多載 `OR` 可以是此節點類型的實方法。Thus, a user-defined overload of the bitwise `OR` operator can be the implementing method for this node type.

• 否則為 `left` 。輸入和 `right` 。類型是布林值類型，實方法是 `null`Otherwise, if `left`.Type and `right`.Type are Boolean types, the implementing method is `null`.

#### 節點類型和提升與未提升Node Type and Lifted versus Non-Lifted

• 如果為，則為 `left` 。輸入和 `right` 。類型可指派給實方法的對應引數類型，而不會引發節點。If `left`.Type and `right`.Type are assignable to the corresponding argument types of the implementing method, the node is not lifted. 節點的型別是實方法的傳回型別。The type of the node is the return type of the implementing method.

• 如果符合下列兩個條件，節點就會被提升，而節點的類型會是可為 null 的型別，該型別會對應至實方法的傳回型別：If the following two conditions are satisfied, the node is lifted and the type of the node is the nullable type that corresponds to the return type of the implementing method:

• `left`.輸入和 `right` 。類型是至少一個可為 null 的實值型別，而對應的不可為 null 的型別等於實方法的對應引數類型。`left`.Type and `right`.Type are both value types of which at least one is nullable, and the corresponding non-nullable types are equal to the corresponding argument types of the implementing method.

• 實方法的傳回型別是不可為 null 的實值型別。The return type of the implementing method is a non-nullable value type.

• `left`.輸入和 `right` 。類型是相同的布林類型。`left`.Type and `right`.Type are the same Boolean type.

• 如果為，則為 `left` 。輸入和 `right` 。類型不可為 null，節點不會被提升。If `left`.Type and `right`.Type are non-nullable, the node is not lifted. 節點的型別是預先定義之條件運算子的結果型別 `OR`The type of the node is the result type of the predefined conditional `OR` operator.

• 如果為，則為 `left` 。輸入和 `right` 。型別可為 null，節點會被提升。If `left`.Type and `right`.Type are nullable, the node is lifted. 節點的型別是可為 null 的型別，它會對應到預先定義之條件運算子的結果型別 `OR`The type of the node is the nullable type that corresponds to the result type of the predefined conditional `OR` operator.