Essential C# Indexer  Suggest an edit

A simple indexer

class Foo
{
    private string[] cities = new[] { "Paris", "London", "Berlin" };

    public string this[int index]
    {
        get {
            return cities[index];
        }
        set {
            cities[index] = value;
        }
    }
}

Usage:

var foo = new Foo();

// access a value    
string berlin = foo[2];

// assign a value
foo[0] = "Rome";

View Demo


Table Of Contents
22 Enum
25 GUID
105 Indexer
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close