> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Default

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).

```csharp theme={"dark"}
// Explicit type specification
TypeName explicitVariable = default(TypeName);

// Target-typed default literal (type is inferred from the declaration)
TypeName inferredVariable = default;
```

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

```csharp theme={"dark"}
// Value Types
int defaultInt = default;               // 0
double defaultDouble = default;         // 0.0
bool defaultBool = default;             // false
char defaultChar = default;             // '\0' (U+0000)

// Reference Types
string defaultString = default;         // null
object defaultObject = default;         // null

// Complex Types
DateTime defaultDate = default;         // 01/01/0001 00:00:00 (DateTime.MinValue)
Guid defaultGuid = default;             // 00000000-0000-0000-0000-000000000000

// Nullable Value Types
int? defaultNullable = default;         // null
```

## 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.

```csharp theme={"dark"}
public class GenericContainer<T>
{
    public T DefaultProperty { get; } = default;
    
    public T GetDefaultValue()
    {
        return default(T); 
    }
}
```

## 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.

```csharp theme={"dark"}
// Valid: Type inferred from variable declaration
int number = default;

// Valid: Type inferred from method signature
void Process(string input) { }
Process(default);

// Valid: Type inferred from return type
bool IsValid() => default;

// Invalid: Cannot infer type (results in compiler error CS0815)
var unknown = default; 
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
