Expression.Default(Type) Metodo

Definizione

Crea un oggetto DefaultExpression con la Type proprietà impostata sul tipo specificato.

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

Parametri

type
Type

Oggetto Type su cui impostare la Type proprietà uguale.

Valori restituiti

Oggetto DefaultExpression con la NodeType proprietà uguale a Default e la Type proprietà impostata sul tipo specificato.

Esempio

Nell'esempio di codice seguente viene illustrato come creare un'espressione che rappresenta un valore predefinito per un determinato tipo.

// 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

Si applica a