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

The `typeof` operator is a unary operator that obtains the `System.Type` instance representing a specific C# type at compile time. It takes a type name or a type parameter as its operand and returns the CLR metadata associated with that type, without requiring an allocated object instance.

```csharp theme={"dark"}
Type typeInfo = typeof(int);
```

## Technical Characteristics

* **Compile-Time Resolution:** The C# compiler resolves the `typeof` expression to a metadata token. During execution, the Common Language Runtime (CLR) translates this token into a `System.Type` object reference.
* **Operand Restrictions:** The operand must be a type name, a generic type parameter, or an unbound generic type. It cannot be a variable, an expression, or an object instance. To obtain type information from an instance at runtime, the `Object.GetType()` method is used instead.
* **Reference Equality:** The CLR guarantees that exactly one `System.Type` object exists per type per application domain. Consequently, multiple invocations of `typeof` for the same type will return the exact same object reference in memory.

## Syntax Variations

The operator handles various type categories, including primitives, custom objects, generics, and special system types.

**Standard and Custom Types**

```csharp theme={"dark"}
Type stringType = typeof(string);
Type customType = typeof(MyClass);
```

**Void Type**
The operator can evaluate the `void` keyword, returning the `System.Void` type. This is strictly used for reflection purposes, as `void` cannot be instantiated.

```csharp theme={"dark"}
Type voidType = typeof(void);
```

**Arrays**
The operator supports array types, including multi-dimensional and jagged arrays.

```csharp theme={"dark"}
Type singleDimArray = typeof(int[]);
Type multiDimArray = typeof(int[,]);
```

**Generic Types**
`typeof` can evaluate both bound (constructed) and unbound generic types. For unbound generics, the syntax omits the type arguments but retains the commas to denote the arity (number of type parameters).

```csharp theme={"dark"}
// Bound generic type
Type boundList = typeof(List<int>);

// Unbound generic type (Arity 1)
Type unboundList = typeof(List<>);

// Unbound generic type (Arity 2)
Type unboundDict = typeof(Dictionary<,>);
```

**Generic Type Parameters**
When used within a generic class or method, `typeof` can evaluate the generic type parameter `T`. The actual `System.Type` returned will depend on the closed constructed type provided at runtime.

```csharp theme={"dark"}
public class GenericClass<T>
{
    public Type GetParameterType()
    {
        return typeof(T);
    }
}
```

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