Expression.Parameter 方法

定義

建立 ParameterExpression 節點,此節點可用以識別運算式樹狀中的參數或變數。

多載

Parameter(Type, String)

建立 ParameterExpression 節點,此節點可用以識別運算式樹狀中的參數或變數。

Parameter(Type)

建立 ParameterExpression 節點,此節點可用以識別運算式樹狀中的參數或變數。

Parameter(Type, String)

來源:
ParameterExpression.cs
來源:
ParameterExpression.cs
來源:
ParameterExpression.cs

建立 ParameterExpression 節點,此節點可用以識別運算式樹狀中的參數或變數。

C#
public static System.Linq.Expressions.ParameterExpression Parameter (Type type, string name);
C#
public static System.Linq.Expressions.ParameterExpression Parameter (Type type, string? name);

參數

type
Type

參數或變數的類型。

name
String

參數或變數的名稱,僅供偵錯或列印之用。

傳回

ParameterExpression,其 NodeType 屬性等於 Parameter,且 TypeName 屬性設定為指定的值。

例外狀況

typenull

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Parameter(Type)

來源:
ParameterExpression.cs
來源:
ParameterExpression.cs
來源:
ParameterExpression.cs

建立 ParameterExpression 節點,此節點可用以識別運算式樹狀中的參數或變數。

C#
public static System.Linq.Expressions.ParameterExpression Parameter (Type type);

參數

type
Type

參數或變數的類型。

傳回

建立含指定之名稱和類型的 ParameterExpression 節點。

範例

下列範例示範如何建立 MethodCallExpression 物件,以列印 物件的值 ParameterExpression

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

// Creating a parameter for the expression tree.
ParameterExpression param = Expression.Parameter(typeof(int));

// Creating an expression for the method call and specifying its parameter.
MethodCallExpression methodCall = Expression.Call(
    typeof(Console).GetMethod("WriteLine", new Type[] { typeof(int) }),
    param
);

// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda<Action<int>>(
    methodCall,
    new ParameterExpression[] { param }
).Compile()(10);

// This code example produces the following output:
//
// 10

適用於

.NET 9 和其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0