There is already an indexer definition in the list, so there is no need to change this code. It will work by default.
public class MyClass : List<int> { }
And we can access the index here. Although we have not implemented anything
MyClass myclass = new MyClass(); myclass.Add(1); int i = myclass[0]; //Fetching the first value in our list ( 1 )
Note that the List class is not intended to be inherited. You must encapsulate it without expanding it. - Service
And it will look like
public class MyClass { private List<int> _InternalList = new List<int>(); public int this[int i] { get { return _InternalList[i]; } set { _InternalList[i] = value; } } }
source share