ConstantExpression Class (System.Linq.Expressions) (original) (raw)

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents an expression that has a constant value.

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

Inheritance

Examples

The following code example shows how to create an expression that represents a constant value by using the Constant method.

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

Remarks

Use the Constant factory methods to create a ConstantExpression.

The NodeType of a ConstantExpression is Constant.

Applies to