Home » C# Default Expression

C# Default Expression

C# default expression is a class (DefaultExpression) that is used to represent default value of an empty expression. It is a sub class of System.Linq.Expressions.Expression namespace.

To get default value of an expression, Expression class provides a static method Default(Type) that returns instance of DefaultExpression class.

C# DefaultExpression class Syntax

It provides following properties and methods.

C# DefaultExpression Properties

Name Description
CanReduce This property is inherited from Expressionn. It Indicates that the node can be reduced to a simpler node.
NodeType It is used to return the node type of this expression.
Type Gets the static type of the expression that this Expression represents.

C# DefaultExpression Methods

Name Description
Accept(ExpressionVisitor) It is used to dispatch the specific visit method for this node type.
Equals(Object) It determines whether the specified object is equal to the current object or not.
GetHashCode() This method serves as the default hash function.
GetType() It is used to get the type of the current instance.
Reduce() It is used to reduce this node to a simpler expression.
ReduceAndCheck() It is used to reduce this node to a simpler expression by explicit checking.
ReduceExtensions() It reduces the expression to a known node type.
ToString() It is used to return a string representation of the Expression.
VisitChildren(ExpressionVisitor) It reduces the node and then calls the visitor delegate on the reduced expression.

The Expression.Default() method has the following signature.

It takes a parameter of System.Type type and returns an instance of DefaultExpression class.

C# Default Expression Example

Output:

Instace:       default(Int32) Type:          System.Int32 Can reduce:    False Instance type: System.Linq.Expressions.DefaultExpression Node type:     Default 

Next TopicC# Programs

You may also like