Expression.Constant Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee maak je een ConstantExpression.
Overloads
| Name | Description |
|---|---|
| Constant(Object) |
Hiermee maakt u een ConstantExpression eigenschap die is Value ingesteld op de opgegeven waarde. |
| Constant(Object, Type) |
Hiermee maakt u een ConstantExpression met de Value en Type eigenschappen die zijn ingesteld op de opgegeven waarden. |
Constant(Object)
Hiermee maakt u een ConstantExpression eigenschap die is Value ingesteld op de opgegeven waarde.
public:
static System::Linq::Expressions::ConstantExpression ^ Constant(System::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
Parameters
Retouren
Een ConstantExpression met de NodeType eigenschap die gelijk is aan Constant en de Value eigenschap is ingesteld op de opgegeven waarde.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u een expressie maakt die een constante waarde vertegenwoordigt.
// 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
Opmerkingen
De Type eigenschap van het resulterende ConstantExpression is gelijk aan het type value. Als value dat het is null, Type is gelijk aan Object.
Als vertegenwoordiger nullkunt u ook de Constant(Object, Type) methode gebruiken waarmee u het type expliciet kunt opgeven.
Van toepassing op
Constant(Object, Type)
Hiermee maakt u een ConstantExpression met de Value en Type eigenschappen die zijn ingesteld op de opgegeven waarden.
public:
static System::Linq::Expressions::ConstantExpression ^ Constant(System::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
Parameters
Retouren
Een ConstantExpression met de NodeType eigenschap gelijk aan Constant en de Value eigenschappen die Type zijn ingesteld op de opgegeven waarden.
Uitzonderingen
type is null.
value is niet null en type kan niet worden toegewezen vanuit het dynamische type value.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u een expressie maakt die een constante van het type null vertegenwoordigt en de waarde ervan instelt op null.
// 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
Opmerkingen
Deze methode kan handig zijn voor het weergeven van waarden van null-typen.