ConstantExpression 類別

定義

代表具有常數值的運算式。

public ref class ConstantExpression : System::Linq::Expressions::Expression
public ref class ConstantExpression sealed : System::Linq::Expressions::Expression
public class ConstantExpression : System.Linq.Expressions.Expression
public sealed class ConstantExpression : System.Linq.Expressions.Expression
type ConstantExpression = class
    inherit Expression
Public Class ConstantExpression
Inherits Expression
Public NotInheritable Class ConstantExpression
Inherits Expression
繼承
ConstantExpression

範例

下列程式碼範例示範如何使用 方法來建立代表常數值 Constant 的運算式。

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

// This expression represents a Constant value.
Expression constantExpr = Expression.Constant(5.5);

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

// You can also use variables.
double num = 3.5;
constantExpr = Expression.Constant(num);
Console.WriteLine(constantExpr.ToString());

// This code example produces the following output:
//
// 5.5
// 3.5
' Add the following directive to your file:
' Imports System.Linq.Expressions 

' This expression represents a constant value.
Dim constantExpr As Expression = Expression.Constant(5.5)

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

' You can also use variables.
Dim num As Double = 3.5
constantExpr = Expression.Constant(num)
Console.WriteLine(constantExpr.ToString())

' This code example produces the following output:
'
' 5.5
' 3.5

備註

Constant使用 Factory 方法來建立 ConstantExpression

NodeTypeConstantExpressionConstant

屬性

CanReduce

表示節點可精簡為更簡單的節點。 如果傳回 true,則可呼叫 Reduce() 以產生精簡的形式。

(繼承來源 Expression)
NodeType

傳回這個 Expression 的節點型別。 覆寫此方法時,擴充節點應傳回 Extension

NodeType

取得這個 Expression 的節點類型。

(繼承來源 Expression)
Type

取得此 Expression 代表之運算式的靜態類型。

Type

取得此 Expression 代表之運算式的靜態類型。

(繼承來源 Expression)
Value

取得常數運算式的值。

方法

Accept(ExpressionVisitor)

分派給這個節點類型的特定造訪方法。 例如,MethodCallExpression 會呼叫 VisitMethodCall(MethodCallExpression)

Accept(ExpressionVisitor)

分派給這個節點類型的特定造訪方法。 例如,MethodCallExpression 會呼叫 VisitMethodCall(MethodCallExpression)

(繼承來源 Expression)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Reduce()

將這個節點精簡為更簡單的運算式。 如果 CanReduce 傳回 true,則應該傳回有效的運算式。 這個方法可以傳回其他本身必須精簡的節點。

(繼承來源 Expression)
ReduceAndCheck()

將這個節點精簡為更簡單的運算式。 如果 CanReduce 傳回 true,則應該傳回有效的運算式。 這個方法可以傳回其他本身必須精簡的節點。

(繼承來源 Expression)
ReduceExtensions()

將運算式精簡為已知的節點類型 (不是 Extension 節點),如果已經是已知的類型,則僅傳回運算式。

(繼承來源 Expression)
ToString()

傳回 Expression 的文字表示。

(繼承來源 Expression)
VisitChildren(ExpressionVisitor)

精簡節點,然後呼叫精簡後的運算式上的訪問項委派。 如果節點無法縮減,此方法會擲回例外狀況。

(繼承來源 Expression)

適用於