Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Default Method
Collapse the table of content
Expand the table of content

Expression.Default Method

Creates a DefaultExpression that has the Type property set to the specified type.

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

Public Shared Function Default ( _
	type As Type _
) As DefaultExpression


Type: System.Type

A Type to set the Type property equal to.

Return Value

Type: System.Linq.Expressions.DefaultExpression
A DefaultExpression that has the NodeType property equal to Default and the Type property set to the specified type.

The following code example shows how to create an expression that represents a default vaule for a given type.

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

' This expression represents the default value of a type 
' (0 for integer, null for a string, and so on). 
Dim defaultExpr As Expression = Expression.Default(

' Print the expression.

' The following statement first creates an expression tree, 
' then compiles it, and then executes it.
    Expression.Lambda(Of Func(Of Byte))(defaultExpr).Compile()())

' This code example produces the following output: 

' default(Byte) 
' 0

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
© 2015 Microsoft