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

An indexer is a specialized class, struct, or interface member that allows instances of a type to be accessed using array access syntax (`[]`). Under the hood, indexers are syntactic sugar for parameterized properties. During compilation, the C# compiler translates indexers into `get_Item` and `set_Item` methods in the Intermediate Language (IL).

## Syntax and Declaration

Indexers are declared using the `this` keyword in place of a member name, followed by the index parameter(s) enclosed in square brackets. Like standard properties, they utilize `get`, `set`, or `init` accessors.

```csharp theme={"dark"}
public ReturnType this[IndexType index]
{
    get { /* return the value specified by index */ }
    set { /* assign the value specified by index */ }
}
```

## Technical Characteristics

* **Signature Matching:** An indexer's signature is defined by the number and types of its parameters. The return type is not part of the signature.
* **Overloading:** A single type can define multiple indexers, provided each has a distinct parameter signature.
* **Non-Integer Indices:** Unlike standard arrays, which strictly require integer indices, indexers can accept parameters of any type (e.g., `string`, `Guid`, `enum`).
* **Multidimensionality:** Indexers can accept multiple parameters to simulate multidimensional array access.
* **Expression-Bodied Members:** Indexers fully support expression-bodied syntax (`=>`) for concise accessor implementation.
* **Modifiers:** Indexers can be marked with access modifiers (`public`, `protected`, etc.), and can be `virtual`, `abstract`, or `override`. They cannot be `static`.

## Implementation Examples

**Basic Single-Parameter Indexer**
This example demonstrates an indexer wrapping a standard array backing store, utilizing expression-bodied accessors.

```csharp theme={"dark"}
public class DataStore
{
    private readonly string[] _backingArray = new string[10];

    public string this[int index]
    {
        get => _backingArray[index];
        set => _backingArray[index] = value;
    }
}
```

**Overloaded Indexer with Non-Integer Type**
This demonstrates indexer overloading where the index parameter is a `string`.

```csharp theme={"dark"}
public class ConfigurationMap
{
    private readonly Dictionary<string, string> _settings = new();

    public string this[string key]
    {
        get => _settings.TryGetValue(key, out var val) ? val : null;
        set => _settings[key] = value;
    }
}
```

**Multidimensional Indexer**
Indexers can declare multiple parameters separated by commas.

```csharp theme={"dark"}
public class Grid
{
    private readonly int[,] _matrix = new int[10, 10];

    public int this[int row, int column]
    {
        get => _matrix[row, column];
        set => _matrix[row, column] = value;
    }
}
```

## Interface Indexers

Indexers can be declared within interfaces. Interface indexers do not have a body; they only declare the required accessors.

```csharp theme={"dark"}
public interface IRegistry
{
    // Declares an indexer requiring both a getter and a setter
    object this[Guid id] { get; set; }
}
```

When implementing an interface indexer, the implementing class must match the exact signature and provide the accessors mandated by the interface. Explicit interface implementation is also supported to hide the indexer from the class's default public API.

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