Expression.Default(Type) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee maakt u een DefaultExpression eigenschap waarvoor de Type eigenschap is ingesteld op het opgegeven 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
Retouren
Een DefaultExpression met de NodeType eigenschap die gelijk is aan Default en de Type eigenschap is ingesteld op het opgegeven type.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u een expressie maakt die een standaardwaarde voor een bepaald type vertegenwoordigt.
// 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