Answer: An indexer is a member which enables an object to be indexed in the same way as an array.
Example:
namespace ConsoleApplication
{
using System;
class Employee
{
private string[]name = new string[10];
public string this[int index]
{
get
{
return name[index];
}
set
{
name[index] = value;
}
}
}
class Test
{
public static void Main()
{
Employee emp = new Employee();
emp[0] = "Joydip";
emp[1] = "Manashi";
emp[2] = "Jini";
Console.WriteLine("The namesare:--");
for (int i = 0; i < 3;Console.WriteLine(emp[i++]))
;
Console.ReadLine();
}
}
}
The output is as follows:
The names are:--
Joydip
Manashi
Jini
Found interesting? Add this to: