A simple indexer
suggest changeclass 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";
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents