Indexer:Why to use it if Public array can solve the purpose
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.

bilnaadRank #2,169 · 655 pointsPosted Dec 14, 2004, 11:56 AM EST
amit_gupta14109 pointsPosted Dec 14, 2004, 6:22 PM EST
bilnaadRank #2,169 · 655 pointsPosted Dec 15, 2004, 10:16 AM EST