Share via


Expression.Type Property

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

Gets the static type of the expression that this Expression represents.

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

Syntax

'Declaration
Public Overridable ReadOnly Property Type As Type
public virtual Type Type { get; }

Property Value

Type: System.Type
The Type that represents the static type of the expression.

Remarks

The NodeType is the type of the expression tree node, whereas the Type represents the static common language runtime (CLR) type of the expression that the node represents. For example, two nodes with different node types can have the same Type, as shown in the following code example.

' Add the following directive to your file:
' Imports System.Linq.Expressions  

Dim constExpr As ConstantExpression = Expression.Constant(5)
outputBlock.Text &= "NodeType: " & constExpr.NodeType.ToString() & vbCrLf
outputBlock.Text &= "Type: " & constExpr.Type.ToString() & vbCrLf

Dim binExpr As BinaryExpression = Expression.Add(constExpr, constExpr)
outputBlock.Text &= "NodeType: " & binExpr.NodeType.ToString() & vbCrLf
outputBlock.Text &= "Type: " & binExpr.Type.ToString() & vbCrLf

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

ConstantExpression constExpr = Expression.Constant(5);
outputBlock.Text += "NodeType: " + constExpr.NodeType + "\n";
outputBlock.Text += "Type: " + constExpr.Type + "\n";

BinaryExpression binExpr = Expression.Add(constExpr, constExpr);
outputBlock.Text += "NodeType: " + binExpr.NodeType + "\n";
outputBlock.Text += "Type: " + binExpr.Type + "\n";

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

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.