1 class SampleCollection<T> 2 { 3 private T[] arr = new T[100]; 4 public T this[int i] 5 { 6 get 7 { 8 return arr[i]; 9 } 10 set 11 { 12 arr[i] = value; 13 } 14 } 15 } 16 17 // This class shows how client code uses the indexer 18 class Program 19 { 20 static void Main(string[] args) 21 { 22 SampleCollection<string> stringCollection = new SampleCollection<string>(); 23 stringCollection[0] = "Hello, World"; 24 System.Console.WriteLine(stringCollection[0]); 25 } 26 }