Tutorial by Examples

class Foo { private string[] cities = new[] { "Paris", "London", "Berlin" }; public string this[int index] { get { return cities[index]; } set { cities[index] = value; } } } Usage...
interface ITable { // an indexer can be declared in an interface object this[int x, int y] { get; set; } } class DataTable : ITable { private object[,] cells = new object[10, 10]; /// <summary> /// implementation of the indexer declared in the interface //...
By overloading the indexer you can create a class that looks and feels like an array but isn't. It will have O(1) get and set methods, can access an element at index 100, and yet still have the size of the elements inside of it. The SparseArray class class SparseArray { Dictionary<...

Page 1 of 1