Expression.Constant Yöntem

Tanım

ConstantExpression oluşturur.

Aşırı Yüklemeler

Name Description
Constant(Object)

Özelliği belirtilen değere ConstantExpression ayarlanmış bir Value oluşturur.

Constant(Object, Type)

ve ConstantExpression özellikleri belirtilen değerlere ayarlanmış bir ValueType oluşturur.

Constant(Object)

Kaynak:
ConstantExpression.cs
Kaynak:
ConstantExpression.cs
Kaynak:
ConstantExpression.cs
Kaynak:
ConstantExpression.cs
Kaynak:
ConstantExpression.cs

Özelliği belirtilen değere ConstantExpression ayarlanmış bir Value oluşturur.

public:
 static System::Linq::Expressions::ConstantExpression ^ Constant(System::Object ^ value);
public static System.Linq.Expressions.ConstantExpression Constant(object value);
public static System.Linq.Expressions.ConstantExpression Constant(object? value);
static member Constant : obj -> System.Linq.Expressions.ConstantExpression
Public Shared Function Constant (value As Object) As ConstantExpression

Parametreler

value
Object

Özelliğinin Object değerine eşit olarak ayarlanması için birValue.

Döndürülenler

ConstantExpression özelliğine NodeType eşit Constant ve Value özelliği belirtilen değere ayarlanmış bir.

Örnekler

Aşağıdaki kod örneği, sabit bir değeri temsil eden bir ifadenin nasıl oluşturulacağını gösterir.

// 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

Açıklamalar

Sonuçta TypeConstantExpression elde edilen özelliği türüne valueeşittir. ise valuenulleşittir TypeObject.

öğesini temsil nulletmek için, türünü açıkça belirtebileceğiniz yöntemini de kullanabilirsiniz Constant(Object, Type) .

Şunlara uygulanır

Constant(Object, Type)

Kaynak:
ConstantExpression.cs
Kaynak:
ConstantExpression.cs
Kaynak:
ConstantExpression.cs
Kaynak:
ConstantExpression.cs
Kaynak:
ConstantExpression.cs

ve ConstantExpression özellikleri belirtilen değerlere ayarlanmış bir ValueType oluşturur.

public:
 static System::Linq::Expressions::ConstantExpression ^ Constant(System::Object ^ value, Type ^ type);
public static System.Linq.Expressions.ConstantExpression Constant(object value, Type type);
public static System.Linq.Expressions.ConstantExpression Constant(object? value, Type type);
static member Constant : obj * Type -> System.Linq.Expressions.ConstantExpression
Public Shared Function Constant (value As Object, type As Type) As ConstantExpression

Parametreler

value
Object

Özelliğinin Object değerine eşit olarak ayarlanması için birValue.

type
Type

Özelliğinin Type değerine eşit olarak ayarlanması için AType.

Döndürülenler

ConstantExpression özelliğine NodeTypeConstant eşit ve ve ValueType özellikleri belirtilen değerlere ayarlanmış bir.

Özel durumlar

type, null'e eşittir.

value, null dinamik türünden typeatanamaz ve value atanamaz.

Örnekler

Aşağıdaki kod örneği, null atanabilir türün sabitini temsil eden ve değerini nullolarak ayarlayan bir ifadenin nasıl oluşturulacağını gösterir.

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

// This expression represents a constant value,
// for which you can explicitly specify the type.
// This can be used, for example, for defining constants of a nullable type.
Expression constantExpr = Expression.Constant(
                            null,
                            typeof(double?)
                        );

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

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

' This expression represents a constant value, 
' for which you can explicitly specify the type. 
' This can be used, for example, for defining constants of a nullable type.
Dim constantExpr As Expression = Expression.Constant(
                            Nothing,
                            GetType(Double?)
                        )

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

' This code example produces the following output:
'
' null

Açıklamalar

Bu yöntem, null atanabilir türlerin değerlerini temsil etmek için yararlı olabilir.

Şunlara uygulanır