Skip to main content
The default operator in C# produces the default value of a specified type. It evaluates the memory allocation for a type and returns its zero-initialized state, which translates to a null reference for reference types and a zeroed bit-pattern for value types.

Syntax

The operator supports two syntactical forms: the explicit default(T) expression and the inferred default literal (introduced in C# 7.1).

Type Resolution Mechanics

The exact value produced by the default operator depends strictly on the Common Type System (CTS) classification of the target type:
  • Reference Types (class, interface, delegate, string, dynamic): Evaluates to null.
  • Numeric Value Types (int, double, decimal, etc.): Evaluates to 0 (or 0.0, 0m).
  • Boolean (bool): Evaluates to false.
  • Structs (Custom Value Types): Evaluates to an instance of the struct where all underlying fields are recursively set to their own default values.
  • Enums: Evaluates to the enumeration member backed by the integer value 0. If no member explicitly defines 0, it still evaluates to 0 cast to the enum type.
  • Nullable Value Types (Nullable<T> or T?): Evaluates to null, which structurally represents an instance where the HasValue property is false.

Syntax Visualization

Behavior in Generic Contexts

When applied to an unconstrained generic type parameter T, the default operator defers resolution until runtime. The compiler cannot determine whether T will be a reference type or a value type, so default or default(T) guarantees safe initialization regardless of the substituted type argument.

Target-Typed Evaluation Rules

When using the default literal (without the parentheses and type name), the C# compiler must be able to infer the target type from the surrounding expression context.
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More