General Sytax for Indexer is as follows:
Code:
<modifier> <return type> this [argument list]
{
get
{
.
.
.
}
set
{
.
.
.
}
}
eg.
Code:
using System;
using System.Collections;
class pqr
{
private string []info = new string[4];
public string this [int index]
{
get
{
return info[index];
}
set
{
info[index] = value;
}
}
}
class Abc
{
public static void Main()
{
pqr p = new pqr();
p[0] = "India";
p[1] = "Kashmir";
p[2] = "B008";
p[3] = "Delhi";
Console.WriteLine("{0},{1},{2},{3}",p[0],p[1],p[2],p[3]);
}
}
Bookmarks