Search code examples
c#listencapsulation

Make object that encapsulates List<> accessable via [] operator?


I have a class that I made that is basically an encapsulated List<> for a certain type. I can access the List items by using [] like if it was an array, but I don't know how to make my new class inherit that ability from List<>. I tried searching for this but I'm pretty sure I don't know how to word correctly what I want to do and found nothing useful.

Thanks!


Solution

  • That's called an indexer:

    public SomeType this[int index] {
        get { }
        set { }
    }