Indexer_string_to_int1.cs
Indexer :
  • public string this [int index]
Code :

using System;
using System.Collections;
//csc Indexer_string_to_int1.cs
namespace ConsoleApplication1
{
class IndexerClass
{
static public int size = 5;
private string[] str1 = new string[size];
public string this [int index]
{
get { return str1[index]; }
set { str1[index] = value; }
}
}

public class Programm
{
public static void Main()
{
string[] b = { "Jan", "Feb", "Mar", "Apr", "May" };
IndexerClass ic = new IndexerClass();
// sync indexer with array
for (int i = 0; i < b.Length; i++ )
{
ic[i] = b[i];
}
//
Console.WriteLine("list Of Months");
for (int j = 0; j < b.Length; j++ )
{
Console.WriteLine(" " + ic[j] + " month index " + j);
}
Console.ReadLine();
}
}
}