indexers_interface.htm

using System;
using System.Collections;
//csc indexers_interface_1.cs
namespace ex_indexer_1
{
public interface I_Index
{
// indexer declaration:
string this[int index]
{
get;
set;
}}
public class test_indexers : I_Index
{
//private int n3= 0 ;
private string[] str_a; // = new ArrayList();
private double[] dd = new double[10];
//private string[] myData;
// index constructor indexers
public test_indexers(int size)
{

str_a = new string[size];
Console.WriteLine(" Constructor parameterized {0} size", size );
for (int i=0; i < size; i++)
{
str_a[i] = "empty";
}
}
public string this[int n1 ]
{
get
{
Console.WriteLine("get array Index : {0}", n1);
return str_a[n1];
}
set
{
str_a[n1] = value;
Console.WriteLine("\tset value {0}",str_a[n1] = value);
}}}
class test {
static void Main()
{
int x = 10;
Console.WriteLine(" ---Constructor ----UnderConstruction " );
test_indexers str = new test_indexers(x);
test_indexers str1 = new test_indexers(x);
Console.WriteLine(" ---Constructor ----Construction- Completed " );
Console.WriteLine(" " );
str[0] = "Hello, World";
System.Console.WriteLine(str[0]);
Console.ReadLine();
System.Console.WriteLine("---view like array--");
str1[0] = "Hello";
str1[1]= "world";
System.Console.WriteLine("{0}{1}{2}",str1[0],"-",str1[1]);
Console.ReadLine();
}}}