© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•8mo ago•
19 replies
Faker

✅ How does an indexer work and why is it important?

Hello, was just reading a bit about indexers. From what I've understood, an indexer allows our class to behave like an array.

My questions are:

1. When we say that our class behave as a array, this mean that each instance created represent an index? Like
MyClass[0]
MyClass[0]
represents the first instance?
2. What does the
this
this
keyword means in the indexer syntax?

public T this[int i]
{
    get => arr[i];
    set => arr[i] = value;
}
public T this[int i]
{
    get => arr[i];
    set => arr[i] = value;
}

3. In order to use an indexer, we must always have one of the attribute declared as a 1D array?
4. Why are indexers important and helpful
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Why and How does this work?
C#CC# / help
5mo ago
✅ what is the .csproj file and why is it important
C#CC# / help
8mo ago
What is a namespace in C# and why is it important
C#CC# / help
13mo ago
❔ ✅ Why does it work like that
C#CC# / help
3y ago