Expression.Default(Type) Expression.Default(Type) Expression.Default(Type) Method

定義

指定した型に設定された DefaultExpression プロパティを含む Type を作成します。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

パラメーター

type
Type Type Type

Type プロパティを等しく設定する TypeA Type to set the Type property equal to.

戻り値

DefaultExpression と等しい NodeType プロパティおよび指定した型に設定された Default プロパティを含む TypeA 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 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

適用対象