Expression.LessThan 方法

定義

建立代表「小於」數值比較的 BinaryExpression

多載

LessThan(Expression, Expression)

建立代表「小於」數值比較的 BinaryExpression

LessThan(Expression, Expression, Boolean, MethodInfo)

建立代表「小於」數值比較的 BinaryExpression

LessThan(Expression, Expression)

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

建立代表「小於」數值比較的 BinaryExpression

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

參數

left
Expression

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

right
Expression

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

傳回

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

例外狀況

leftrightnull

不會為 left.Type 和 right.Type 定義「小於」運算子。

範例

下列程式碼範例示範如何建立比較兩個整數的運算式。

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

// This expression compares the values of its two arguments.
// Both arguments must be of the same type.
Expression lessThanExpr = Expression.LessThan(
    Expression.Constant(42),
    Expression.Constant(45)
);

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

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

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

' This expression compares the values of its two arguments.
' Both arguments must be of the same type.
Dim lessThanExpr As Expression = Expression.LessThan(
    Expression.Constant(42),
    Expression.Constant(45)
)

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

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

' This code example produces the following output:
'
' (42 < 45)
' True

備註

產生的 BinaryExpression 屬性 Method 會設定為實作方法。 屬性 Type 會設定為節點的類型。 如果節點隨即提升,則 IsLifted 屬性為 true 。 否則,會是 falseIsLiftedToNull 屬性一律為 falseConversion 屬性為 null

下列資訊描述實作方法、節點類型,以及節點是否已隨即提升。

實作方法

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

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

  • 否則,如果 left 為 。輸入 和 right 。類型為數數值型別,實作方法為 null

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

如果實作方法不是 null

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

  • 如果滿足下列兩個條件,則會隨即啟動節點,而節點的類型為 Boolean

    • left.輸入 和 right 。類型都是至少一個可為 Null 且對應的不可為 Null 型別等於實作方法的對應引數型別。

    • 實作方法的傳回型別為 Boolean

如果實作方法為 null

  • 如果為 left 。輸入 和 right 。類型都是不可為 Null 的,節點不會隨即解除。 節點的類型為 Boolean

  • 如果為 left 。輸入 和 right 。類型都是可為 Null 的,節點會隨即解除。 節點的類型為 Boolean

適用於

LessThan(Expression, Expression, Boolean, MethodInfo)

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

建立代表「小於」數值比較的 BinaryExpression

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

參數

left
Expression

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

right
Expression

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

liftToNull
Boolean

true 表示將 IsLiftedToNull 設定為 truefalse 則表示將 IsLiftedToNull 設定為 false

method
MethodInfo

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

傳回

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

例外狀況

leftrightnull

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

methodnull,而且未定義 left.Type 和 right.Type 的「小於」運算子。

備註

產生的 BinaryExpression 屬性 Method 會設定為實作方法。 屬性 Type 會設定為節點的類型。 如果節點隨即提升,則 IsLifted 屬性為 true ,且 IsLiftedToNull 屬性等於 liftToNull 。 否則,兩者都是 falseConversion 屬性為 null

下列資訊描述實作方法、節點類型,以及節點是否已隨即提升。

實作方法

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

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

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

  • 否則,如果 left 為 。輸入 和 right 。類型為數數值型別,實作方法為 null

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

如果實作方法不是 null

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

  • 如果滿足下列兩個條件,則會隨即啟動節點;此外,如果 為 ,則節點的類型可為 Boolean Null;如果 liftToNulltrueBoolean 則為 liftToNullfalse

    • left.輸入 和 right 。類型都是至少一個可為 Null 且對應的不可為 Null 型別等於實作方法的對應引數型別。

    • 實作方法的傳回型別為 Boolean

如果實作方法為 null

  • 如果為 left 。輸入 和 right 。類型都是不可為 Null 的,節點不會隨即解除。 節點的類型為 Boolean

  • 如果為 left 。輸入 和 right 。類型都是可為 Null 的,節點會隨即解除。 如果 為 ,則節點的類型可為 Boolean Null,如果 為 trueBooleanliftToNullliftToNullfalse

適用於