Поделиться через


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

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Linq.Expressions
Assembly:  System.Core (in System.Core.dll)

Syntax

'Declaration
Public Shared Function Lambda(Of TDelegate) ( _
    body As Expression, _
    parameters As IEnumerable(Of ParameterExpression) _
) As Expression(Of TDelegate)
public static Expression<TDelegate> Lambda<TDelegate>(
    Expression body,
    IEnumerable<ParameterExpression> parameters
)

Type Parameters

  • TDelegate
    A delegate type.

Parameters

Return Value

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

Exceptions

Exception Condition
ArgumentNullException

body is nulla null reference (Nothing in Visual Basic).

-or-

One or more elements in parameters are nulla null reference (Nothing in Visual Basic).

ArgumentException

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 nulla null reference (Nothing in Visual Basic), the Parameters property of the resulting object is an empty collection.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.