Indexers Questions | Sololearn: Learn to code for FREE!


Indexers Questions

I just finished the Indexer's chapter and I have some questions: a) What is the advantage of Indexers over a normal array? The only thing I see is how you get to the value: object[2] instead of object.arr [2]. b) Can you have more than an indexer for an object of a class? For example one for int type and another for char type? Thanks for taking your time to read this.

1/12/2017 8:11:54 AM

Andres G

2 Answers

New Answer


indexer is basically a feature so that when you make your own classes then their objects could have a functionality like this object[ ]. Suppose you make your own array class or any other class and want to access its elements using the [ ] operator then you must have written an indexer in that class which will tell what happens when [ ] operator is used with the objects of that class.In short indexers and array are not be compared. indexer is just a feature you give to your class For your second question. you must learn generics to find a way around for multiple indexers otherwise you cant have more than one indexer.


good luck