Expression.Default(Type) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a DefaultExpression that has the Type property set to the specified type.
public:
static System::Linq::Expressions::DefaultExpression ^ Default(Type ^ type);
public static System.Linq.Expressions.DefaultExpression Default (Type type);
static member Default : Type -> System.Linq.Expressions.DefaultExpression
Public Shared Function Default (type As Type) As DefaultExpression
Parameters
Returns
A DefaultExpression that has the NodeType property equal to Default and the Type property set to the specified type.
Examples
The following code example shows how to create an expression that represents a default value for a given type.
// Add the following directive to your file:
// using System.Linq.Expressions;
// This expression represents the default value of a type
// (0 for integer, null for a string, etc.)
Expression defaultExpr = Expression.Default(
typeof(byte)
);
// Print out the expression.
Console.WriteLine(defaultExpr.ToString());
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(
Expression.Lambda<Func<byte>>(defaultExpr).Compile()());
// This code example produces the following output:
//
// default(Byte)
// 0
' 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(
GetType(Byte)
)
' Print the expression.
Console.WriteLine(defaultExpr.ToString())
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(
Expression.Lambda(Of Func(Of Byte))(defaultExpr).Compile()())
' This code example produces the following output:
'
' default(Byte)
' 0
Applies to
Співпраця з нами на GitHub
Джерело цього вмісту можна знайти на GitHub, де також можна створювати й переглядати запитання та запити на внесення змін. Докладні відомості наведено в нашому посібнику для співавторів.