Expression.Lambda Expression.Lambda Expression.Lambda Expression.Lambda Method

Definition

Creates an expression tree that represents a lambda expression.

Overloads

Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Type, Expression, String, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Type, Expression, ParameterExpression[]) Lambda(Type, Expression, ParameterExpression[]) Lambda(Type, Expression, ParameterExpression[]) Lambda(Type, Expression, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type. It can be used when the delegate type is not known at compile time.

Lambda(Type, Expression, Boolean, ParameterExpression[]) Lambda(Type, Expression, Boolean, ParameterExpression[]) Lambda(Type, Expression, Boolean, ParameterExpression[]) Lambda(Type, Expression, Boolean, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Expression, String, IEnumerable<ParameterExpression>) Lambda(Expression, String, IEnumerable<ParameterExpression>) Lambda(Expression, String, IEnumerable<ParameterExpression>) Lambda(Expression, String, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Expression, Boolean, ParameterExpression[]) Lambda(Expression, Boolean, ParameterExpression[]) Lambda(Expression, Boolean, ParameterExpression[]) Lambda(Expression, Boolean, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Type, Expression, IEnumerable<ParameterExpression>) Lambda(Type, Expression, IEnumerable<ParameterExpression>) Lambda(Type, Expression, IEnumerable<ParameterExpression>) Lambda(Type, Expression, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type. It can be used when the delegate type is not known at compile time.

Lambda(Expression, ParameterExpression[]) Lambda(Expression, ParameterExpression[]) Lambda(Expression, ParameterExpression[]) Lambda(Expression, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type.

Lambda(Expression, IEnumerable<ParameterExpression>) Lambda(Expression, IEnumerable<ParameterExpression>) Lambda(Expression, IEnumerable<ParameterExpression>) Lambda(Expression, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time.

Lambda<TDelegate>(Expression, Boolean, ParameterExpression[]) Lambda<TDelegate>(Expression, Boolean, ParameterExpression[]) Lambda<TDelegate>(Expression, Boolean, ParameterExpression[]) Lambda<TDelegate>(Expression, Boolean, ParameterExpression[])

Creates an Expression<TDelegate> where the delegate type is known at compile time.

Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time.

Lambda<TDelegate>(Expression, ParameterExpression[]) Lambda<TDelegate>(Expression, ParameterExpression[]) Lambda<TDelegate>(Expression, ParameterExpression[]) Lambda<TDelegate>(Expression, ParameterExpression[])

Creates an Expression<TDelegate> where the delegate type is known at compile time.

Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time.

Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time.

Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, System::String ^ name, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, string name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * string * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, name As String, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression
Parameters
delegateType
Type Type Type Type

A Type representing the delegate signature for the lambda.

body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

name
String String String String

The name for the lambda. Used for emitting debug information.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda(Type, Expression, String, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, IEnumerable<ParameterExpression>) Lambda(Type, Expression, String, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, System::String ^ name, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, string name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * string * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, name As String, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression
Parameters
delegateType
Type Type Type Type

A Type representing the delegate signature for the lambda.

body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

name
String String String String

The name for the lambda. Used for emitting debug information.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Type, Expression, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression
Parameters
delegateType
Type Type Type Type

A Type representing the delegate signature for the lambda.

body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, System::String ^ name, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, string name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : System.Linq.Expressions.Expression * string * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, name As String, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression
Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

name
String String String String

The name for the lambda. Used for emitting debug information.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda(Type, Expression, ParameterExpression[]) Lambda(Type, Expression, ParameterExpression[]) Lambda(Type, Expression, ParameterExpression[]) Lambda(Type, Expression, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type. It can be used when the delegate type is not known at compile time.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[] parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, ParamArray parameters As ParameterExpression()) As LambdaExpression
Parameters
delegateType
Type Type Type Type

A Type that represents a delegate signature for the lambda.

body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

parameters
ParameterExpression[]

An array of ParameterExpression objects to use to populate the Parameters collection.

Returns

An object that represents a lambda expression which has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

delegateType or body is null.

-or-

One or more elements in parameters are null.

delegateType does not represent a delegate type.

-or-

body.Type represents a type that is not assignable to the return type of the delegate type represented by delegateType.

-or-

parameters does not contain the same number of elements as the list of parameters for the delegate type represented by delegateType.

-or-

The Type property of an element of parameters is not assignable from the type of the corresponding parameter type of the delegate type represented by delegateType.

Remarks

The object that is returned from this function is of type Expression<TDelegate>. The LambdaExpression type is used to represent the returned object because the concrete type of the lambda expression is not known at compile time.

The number of parameters for the delegate type represented by delegateType must equal the length of parameters.

The elements of parameters must be reference equal to the parameter expressions in body.

The Type property of the resulting object is equal to delegateType. If parameters is null, the Parameters property of the resulting object is an empty collection.

Lambda(Type, Expression, Boolean, ParameterExpression[]) Lambda(Type, Expression, Boolean, ParameterExpression[]) Lambda(Type, Expression, Boolean, ParameterExpression[]) Lambda(Type, Expression, Boolean, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, bool tailCall, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[] parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * bool * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, tailCall As Boolean, ParamArray parameters As ParameterExpression()) As LambdaExpression
Parameters
delegateType
Type Type Type Type

A Type representing the delegate signature for the lambda.

body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
ParameterExpression[]

An array that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda(Expression, String, IEnumerable<ParameterExpression>) Lambda(Expression, String, IEnumerable<ParameterExpression>) Lambda(Expression, String, IEnumerable<ParameterExpression>) Lambda(Expression, String, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, System::String ^ name, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, string name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : System.Linq.Expressions.Expression * string * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, name As String, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression
Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

name
String String String String

The name for the lambda. Used for emitting debug information.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda(Expression, Boolean, ParameterExpression[]) Lambda(Expression, Boolean, ParameterExpression[]) Lambda(Expression, Boolean, ParameterExpression[]) Lambda(Expression, Boolean, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, bool tailCall, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[] parameters);
static member Lambda : System.Linq.Expressions.Expression * bool * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, tailCall As Boolean, ParamArray parameters As ParameterExpression()) As LambdaExpression
Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
ParameterExpression[]

An array that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda(Expression, Boolean, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : System.Linq.Expressions.Expression * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression
Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda(Type, Expression, IEnumerable<ParameterExpression>) Lambda(Type, Expression, IEnumerable<ParameterExpression>) Lambda(Type, Expression, IEnumerable<ParameterExpression>) Lambda(Type, Expression, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type. It can be used when the delegate type is not known at compile time.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(Type ^ delegateType, System::Linq::Expressions::Expression ^ body, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.LambdaExpression Lambda (Type delegateType, System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : Type * System.Linq.Expressions.Expression * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (delegateType As Type, body As Expression, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression
Parameters
delegateType
Type Type Type Type

A Type that represents a delegate signature for the lambda.

body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An object that represents a lambda expression which has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

delegateType or body is null.

-or-

One or more elements in parameters are null.

delegateType does not represent a delegate type.

-or-

body.Type represents a type that is not assignable to the return type of the delegate type represented by delegateType.

-or-

parameters does not contain the same number of elements as the list of parameters for the delegate type represented by delegateType.

-or-

The Type property of an element of parameters is not assignable from the type of the corresponding parameter type of the delegate type represented by delegateType.

Examples

The following example demonstrates how to create an expression that represents a lambda expression that adds 1 to the passed argument.

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

// A parameter for the lambda expression.
ParameterExpression paramExpr = Expression.Parameter(typeof(int), "arg");

// This expression represents a lambda expression
// that adds 1 to the parameter value.
LambdaExpression lambdaExpr = Expression.Lambda(
    Expression.Add(
        paramExpr,
        Expression.Constant(1)
    ),
    new List<ParameterExpression>() { paramExpr }
);

// Print out the expression.
Console.WriteLine(lambdaExpr);

// Compile and run the lamda expression.
// The value of the parameter is 1.
Console.WriteLine(lambdaExpr.Compile().DynamicInvoke(1));

// This code example produces the following output:
//
// arg => (arg +1)
// 2
' Add the following directive to your file:
' Imports System.Linq.Expressions  

' A parameter for the lambda expression.
Dim paramExpr As ParameterExpression = Expression.Parameter(GetType(Integer), "arg")

' This expression represents a lambda expression
' that adds 1 to the parameter value.
Dim lambdaExpr As LambdaExpression = Expression.Lambda(
        Expression.Add(
            paramExpr,
            Expression.Constant(1)
        ),
        New List(Of ParameterExpression)() From {paramExpr}
    )

' Print out the expression.
Console.WriteLine(lambdaExpr)

' Compile and run the lamda expression.
' The value of the parameter is 1.
Console.WriteLine(lambdaExpr.Compile().DynamicInvoke(1))

' This code example produces the following output:
'
' arg => (arg +1)
' 2

Remarks

The object that is returned from this function is of type Expression<TDelegate>. The LambdaExpression type is used to represent the returned object because the concrete type of the lambda expression is not known at compile time.

The number of parameters for the delegate type represented bydelegateType must equal the length of parameters.

The elements of parameters must be reference equal to the parameter expressions in body.

The Type property of the resulting object is equal to delegateType. If parameters is null, the Parameters property of the resulting object is an empty collection.

Lambda(Expression, ParameterExpression[]) Lambda(Expression, ParameterExpression[]) Lambda(Expression, ParameterExpression[]) Lambda(Expression, ParameterExpression[])

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[] parameters);
static member Lambda : System.Linq.Expressions.Expression * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, ParamArray parameters As ParameterExpression()) As LambdaExpression
Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

parameters
ParameterExpression[]

An array of ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

body is null.

-or-

One or more elements of parameters are null.

parameters contains more than sixteen elements.

Remarks

The parameters parameter must not have more than sixteen elements.

The elements of parameters must be reference equal to the parameter expressions in body.

This method constructs an appropriate delegate type from one of the System.Func generic delegates. It then passes the delegate type to one of the Lambda factory methods to create a LambdaExpression.

Lambda(Expression, IEnumerable<ParameterExpression>) Lambda(Expression, IEnumerable<ParameterExpression>) Lambda(Expression, IEnumerable<ParameterExpression>) Lambda(Expression, IEnumerable<ParameterExpression>)

Creates a LambdaExpression by first constructing a delegate type.

public:
 static System::Linq::Expressions::LambdaExpression ^ Lambda(System::Linq::Expressions::Expression ^ body, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.LambdaExpression Lambda (System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : System.Linq.Expressions.Expression * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.LambdaExpression
Public Shared Function Lambda (body As Expression, parameters As IEnumerable(Of ParameterExpression)) As LambdaExpression
Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

A LambdaExpression that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, System::String ^ name, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, string name, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : System.Linq.Expressions.Expression * string * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, name As String, parameters As IEnumerable(Of ParameterExpression)) As Expression(Of TDelegate)
Type Parameters
TDelegate

The delegate type.

Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

name
String String String String

The name of the lambda. Used for generating debugging information.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda<TDelegate>(Expression, Boolean, ParameterExpression[]) Lambda<TDelegate>(Expression, Boolean, ParameterExpression[]) Lambda<TDelegate>(Expression, Boolean, ParameterExpression[]) Lambda<TDelegate>(Expression, Boolean, ParameterExpression[])

Creates an Expression<TDelegate> where the delegate type is known at compile time.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, bool tailCall, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, bool tailCall, params System.Linq.Expressions.ParameterExpression[] parameters);
static member Lambda : System.Linq.Expressions.Expression * bool * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, tailCall As Boolean, ParamArray parameters As ParameterExpression()) As Expression(Of TDelegate)
Type Parameters
TDelegate

The delegate type.

Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
ParameterExpression[]

An array that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, String, Boolean, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, System::String ^ name, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, string name, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : System.Linq.Expressions.Expression * string * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, name As String, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As Expression(Of TDelegate)
Type Parameters
TDelegate

The delegate type.

Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

name
String String String String

The name of the lambda. Used for generating debugging info.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Lambda<TDelegate>(Expression, ParameterExpression[]) Lambda<TDelegate>(Expression, ParameterExpression[]) Lambda<TDelegate>(Expression, ParameterExpression[]) Lambda<TDelegate>(Expression, ParameterExpression[])

Creates an Expression<TDelegate> where the delegate type is known at compile time.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, ... cli::array <System::Linq::Expressions::ParameterExpression ^> ^ parameters);
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, params System.Linq.Expressions.ParameterExpression[] parameters);
static member Lambda : System.Linq.Expressions.Expression * System.Linq.Expressions.ParameterExpression[] -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, ParamArray parameters As ParameterExpression()) As Expression(Of TDelegate)
Type Parameters
TDelegate

A delegate type.

Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

parameters
ParameterExpression[]

An array of ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

body is null.

-or-

One or more elements in parameters are null.

TDelegate is not a delegate type.

-or-

body.Type represents a type that is not assignable to the return type of TDelegate.

-or-

parameters does not contain the same number of elements as the list of parameters for TDelegate.

-or-

The Type property of an element of parameters is not assignable from the type of the corresponding parameter type of TDelegate.

Remarks

The number of parameters for the delegate type TDelegate must equal the number of elements in parameters.

The elements of parameters must be reference equal to the parameter expressions inbody.

The Type property of the resulting object represents the type TDelegate. If parameters is null, the Parameters property of the resulting object is an empty collection.

Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : System.Linq.Expressions.Expression * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, parameters As IEnumerable(Of ParameterExpression)) As Expression(Of TDelegate)
Type Parameters
TDelegate

A delegate type.

Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Exceptions

body is null.

-or-

One or more elements in parameters are null.

TDelegate is not a delegate type.

-or-

body.Type represents a type that is not assignable to the return type of TDelegate.

-or-

parameters does not contain the same number of elements as the list of parameters for TDelegate.

-or-

The Type property of an element of parameters is not assignable from the type of the corresponding parameter type of TDelegate.

Remarks

The number of parameters for the delegate type TDelegate must equal the number of elements in parameters.

The elements of parameters must be reference equal to the parameter expressions in body.

The Type property of the resulting object represents the type TDelegate. If parameters is null, the Parameters property of the resulting object is an empty collection.

Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>) Lambda<TDelegate>(Expression, Boolean, IEnumerable<ParameterExpression>)

Creates an Expression<TDelegate> where the delegate type is known at compile time.

public:
generic <typename TDelegate>
 static System::Linq::Expressions::Expression<TDelegate> ^ Lambda(System::Linq::Expressions::Expression ^ body, bool tailCall, System::Collections::Generic::IEnumerable<System::Linq::Expressions::ParameterExpression ^> ^ parameters);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public static System.Linq.Expressions.Expression<TDelegate> Lambda<TDelegate> (System.Linq.Expressions.Expression body, bool tailCall, System.Collections.Generic.IEnumerable<System.Linq.Expressions.ParameterExpression> parameters);
static member Lambda : System.Linq.Expressions.Expression * bool * seq<System.Linq.Expressions.ParameterExpression> -> System.Linq.Expressions.Expression<'Delegate>
Public Shared Function Lambda(Of TDelegate) (body As Expression, tailCall As Boolean, parameters As IEnumerable(Of ParameterExpression)) As Expression(Of TDelegate)
Type Parameters
TDelegate

The delegate type.

Parameters
body
Expression Expression Expression Expression

An Expression to set the Body property equal to.

tailCall
Boolean Boolean Boolean Boolean

A Boolean that indicates if tail call optimization will be applied when compiling the created expression.

parameters
IEnumerable<ParameterExpression>

An IEnumerable<T> that contains ParameterExpression objects to use to populate the Parameters collection.

Returns

An Expression<TDelegate> that has the NodeType property equal to Lambda and the Body and Parameters properties set to the specified values.

Applies to