Indexer In C# .NET

It is a way to access the elements of the class that represent a list of value. Indexer does not have a name so in methods or property declaration we can use this keyword.
public class IndexerDemo
{

private readonly Dictionary<string, string> _dic;

public IndexerDemo()
{
    _dic = new Dictionary<string, string>();
}

public string this[string key]
{
    get {
        return _dic[key];
    }
    set
    {
        _dic[key] = value;
    }
}

}
In calling methods
IndexerDemo indexer = new IndexerDemo();
indexer[“name”]=“sagar”;
indexer[“surname”] = “jaybhay”;

        Console.WriteLine(indexer["name"]+ " "+indexer["surname"]);
.NET Foundation Website | Blog | Projects | Code of Conduct