Expression.Default(Type) メソッド

定義

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

パラメーター

type
Type

Type プロパティを等しく設定する Type

戻り値

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

適用対象