Friday, February 23, 2007

Ay...ay...ay...ay...ay... Indexers!

Indexers provide array-like access to any objects. Here's an example that demonstrates how to use them:

class myIndexerGeneric
{
private T[] indxr = new T[10];
public T this[int i]
{
get { return indxr[i]; }
set { indxr[i] = value; }
}
}


private void TestIndexer()
{
ArrayList a = new ArrayList();
a.Add("TextIn");

myIndexerGeneric<ArrayList> g = new myIndexerGeneric<ArrayList>();
g[0] = a;

ArrayList b = new ArrayList();
b = g[0];
}

No comments: