• Indexers can be viewed as a smart array,
  • Indexers are similar to properties except that their accessors take parameters.
  • This "this" stands as suffix to the class
    • public type this [int index] // Indexer declaration
    • public int this [int index] // Indexer declaration Integer parameter
    • public string this [string index] // Indexer declaration string parameter
Code Used :

using System;
using System.Collections;
//csc Indexer_this1.cs
namespace ConsoleApplication1
class LikeHashtable
string str1; object obj1; // private default
public LikeHashtable() { Console.WriteLine("default constructor"); }
~LikeHashtable() { Console.WriteLine("destructor fired"); }
public LikeHashtable(string str1, object obj1)
this.str1 = str1; this.obj1 = obj1;
public string myString
get { return (str1); } set { str1 = value; }
public object myObject
get { return (obj1); } set { obj1 = value; }


class Programm
static void Main(string[] args)
Console.WriteLine("Your name please");
LikeHashtable likehash = new LikeHashtable();
ArrayList row = new ArrayList();
row.Add(likehash = new LikeHashtable("string integer", 1234));
readme(likehash.myString, likehash.myObject);
row.Add(likehash = new LikeHashtable("both strings", "some string"));
readme(likehash.myString, likehash.myObject);
static void readme(string str, Object obj)
Console.WriteLine(obj + " : " + str);


Debugging; Stepping with F11
Command Prompt:

Under an ArrayList

Pointier moves to

All the objects are initialized : Not Set and Get in "mystring" property

At the end of completing first feed , cursor returns to the point of origin.

Next the objects were passed to a method, to display the values.

Command line, displays the output.

Now cursor moves to second feed:

The old value willbe replaced with the new ones

And at the end command lien would display the total output of this applicaton.

Command Line : display