3
Answers

Indexer:Why to use it if Public array can solve the purpose

amit_gupta14

amit_gupta14

19y
2.4k
1
1. If public array can solve the purpose, then why to use indexer 2.There is array member private int [] myArray = new int[100]; in class say c1. I have used the following code to use indexer public int this [int index] // Indexer declaration { get { // Check the index limits. if (index < 0 || index >= 100) return 0; else return myArray[index]; } set { if (!(index < 0 || index >= 100)) myArray[index] = value; } } It is working fine. But say there is another member private string [] myArray11 = new string[100]; in the same class along with previous member, then how to use indexer for it.
Answers (3)