Expression.LessThan 方法

定義

建立代表「小於」數值比較的 BinaryExpressionCreates a BinaryExpression that represents a "less than" numeric comparison.

多載

LessThan(Expression, Expression)

建立代表「小於」數值比較的 BinaryExpressionCreates a BinaryExpression that represents a "less than" numeric comparison.

LessThan(Expression, Expression, Boolean, MethodInfo)

建立代表「小於」數值比較的 BinaryExpressionCreates a BinaryExpression that represents a "less than" numeric comparison.

LessThan(Expression, Expression)

建立代表「小於」數值比較的 BinaryExpressionCreates a BinaryExpression that represents a "less than" numeric comparison.

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 屬性設定為與之相等的 LeftAn Expression to set the Left property equal to.

right
Expression

要將 Expression 屬性設定為與之相等的 RightAn Expression to set the Right property equal to.

傳回

BinaryExpression

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

例外狀況

leftrightnullleft or right is null.

不會為 left.Type 和 right.Type 定義「小於」運算子。The "less than" operator is not defined for left.Type and right.Type.

範例

下列程式碼範例顯示如何建立比較兩個整數的運算式。The following code example shows how to create an expression that compares two integers.

// 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 設定為實方法。The resulting BinaryExpression has the Method property set to the implementing method. Type屬性會設定為節點的型別。The Type property is set to the type of the node. 如果已提升節點,則 IsLifted 屬性為 trueIf the node is lifted, the IsLifted property is true. 否則,會是 falseOtherwise, it is false. IsLiftedToNull 屬性一律為 falseThe IsLiftedToNull property is always false. Conversion 屬性為 nullThe Conversion property is null.

下列資訊描述實方法、節點型別,以及是否要提升節點。The following information describes the implementing method, the node type, and whether a node is lifted.

實方法Implementing Method

作業的實方法是根據下列規則選擇:The implementing method for the operation is chosen based on the following rules:

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

  • 否則為 left 。輸入和 right 。類型為數數值型別,實方法為 nullOtherwise, if left.Type and right.Type are numeric types, the implementing method is null.

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

如果執行中的方法不是 nullIf the implementing method is not null:

  • 如果為,則為 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.

  • 如果符合下列兩個條件,節點就會被提升,節點的類型為 BooleanIf the following two conditions are satisfied, the node is lifted and the type of the node is Boolean:

    • 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.

    • 實方法的傳回型別為 BooleanThe return type of the implementing method is Boolean.

如果實方法為 nullIf the implementing method is null:

  • 如果為,則為 left 。輸入和 right 。類型不可為 null,節點不會被提升。If left.Type and right.Type are both non-nullable, the node is not lifted. 節點的類型是 BooleanThe type of the node is Boolean.

  • 如果為,則為 left 。輸入和 right 。型別可以是可為 null,而是會提升節點。If left.Type and right.Type are both nullable, the node is lifted. 節點的類型是 BooleanThe type of the node is Boolean.

適用於

LessThan(Expression, Expression, Boolean, MethodInfo)

建立代表「小於」數值比較的 BinaryExpressionCreates a BinaryExpression that represents a "less than" numeric comparison.

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 屬性設定為與之相等的 LeftAn Expression to set the Left property equal to.

right
Expression

要將 Expression 屬性設定為與之相等的 RightAn Expression to set the Right property equal to.

liftToNull
Boolean

true 表示將 IsLiftedToNull 設定為 truefalse 則表示將 IsLiftedToNull 設定為 falsetrue to set IsLiftedToNull to true; false to set IsLiftedToNull to false.

method
MethodInfo

要將 MethodInfo 屬性設定為與之相等的 MethodA MethodInfo to set the Method property equal to.

傳回

BinaryExpression

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

例外狀況

leftrightnullleft 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.

methodnull,而且未定義 left.Type 和 right.Type 的「小於」運算子。method is null and the "less than" operator is not defined for left.Type and right.Type.

備註

產生的 BinaryExpression 屬性會 Method 設定為實方法。The resulting BinaryExpression has the Method property set to the implementing method. Type屬性會設定為節點的型別。The Type property is set to the type of the node. 如果節點已提升, IsLifted 屬性為, true 而且 IsLiftedToNull 屬性等於 liftToNullIf the node is lifted, the IsLifted property is true and the IsLiftedToNull property is equal to liftToNull. 否則,兩者都是 falseOtherwise, they are both false. Conversion 屬性為 nullThe Conversion property is null.

下列資訊描述實方法、節點型別,以及是否要提升節點。The following information describes the implementing method, the node type, and whether a node is lifted.

實方法Implementing Method

下列規則決定作業的實方法:The following rules determine the implementing method for the operation:

  • 如果不 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.

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

  • 否則為 left 。輸入和 right 。類型為數數值型別,實方法為 nullOtherwise, if left.Type and right.Type are numeric types, the implementing method is null.

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

如果執行中的方法不是 nullIf the implementing method is not null:

  • 如果為,則為 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.

  • 如果滿足下列兩個條件,則會引發節點;此外, Boolean 如果是或,則節點的型別可為 null liftToNull true Boolean liftToNull falseIf the following two conditions are satisfied, the node is lifted; also, the type of the node is nullable Boolean if liftToNull is true or Boolean if liftToNull is false:

    • 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.

    • 實方法的傳回型別為 BooleanThe return type of the implementing method is Boolean.

如果實方法為 nullIf the implementing method is null:

  • 如果為,則為 left 。輸入和 right 。類型不可為 null,節點不會被提升。If left.Type and right.Type are both non-nullable, the node is not lifted. 節點的類型是 BooleanThe type of the node is Boolean.

  • 如果為,則為 left 。輸入和 right 。型別可以是可為 null,而是會提升節點。If left.Type and right.Type are both nullable, the node is lifted. Boolean如果 liftToNulltrueBoolean liftToNull ,則節點的型別可為 null falseThe type of the node is nullable Boolean if liftToNull is true or Boolean if liftToNull is false.

適用於