Expression.Type 属性

定义

获取此 Expression 表示的表达式的静态类型。

public:
 virtual property Type ^ Type { Type ^ get(); };
public:
 property Type ^ Type { Type ^ get(); };
public virtual Type Type { get; }
public Type Type { get; }
member this.Type : Type
Public Overridable ReadOnly Property Type As Type
Public ReadOnly Property Type As Type

属性值

表示表达式的静态类型的 Type

注解

NodeType是表达式树节点的类型,而 Type 表示静态公共语言运行时 (CLR) 节点表示的表达式类型。 例如,具有不同节点类型的两个节点可以具有相同 Type的 ,如以下代码示例中所示。

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

ConstantExpression constExpr = Expression.Constant(5);
Console.WriteLine("NodeType: " + constExpr.NodeType);
Console.WriteLine("Type: " + constExpr.Type);

BinaryExpression binExpr = Expression.Add(constExpr, constExpr);
Console.WriteLine("NodeType: " + binExpr.NodeType);
Console.WriteLine("Type: " + binExpr.Type);

// This code example produces the following output:
//
// NodeType: Constant
// Type: System.Int32
// NodeType: Add
// Type: System.Int32
' Add the following directive to your file:
' Imports System.Linq.Expressions  

Dim constExpr As ConstantExpression = Expression.Constant(5)
Console.WriteLine("NodeType: " & constExpr.NodeType.ToString())
Console.WriteLine("Type: " & constExpr.Type.ToString())

Dim binExpr As BinaryExpression = Expression.Add(constExpr, constExpr)
Console.WriteLine("NodeType: " & binExpr.NodeType.ToString())
Console.WriteLine("Type: " & binExpr.Type.ToString())

' This code example produces the following output:
'
' NodeType: Constant
' Type: System.Int32
' NodeType: Add
' Type: System.Int32

适用于