dear friends
i was trying to use indexer as auto-implementing properties as i think that indexer is nothing but properties just the difference is its syntax but i got an exception which was something about stack over flow i don't know why it showing so though i have not done any infinite looping or recursion i will try to attach screen print of program which i did please help me what wrong i did.
using System;
namespace IndexerExample
{
class Employee
{
public int this[int index]
{
get {
return this[index];
}
set {
this[index]=value;
}
}
}
class Program
{
static void Main(string[] args)
{
Employee e = new Employee();
e[0] = 2;
Console.WriteLine(e[0]);
Console.ReadLine();
}
}
}

VulpesPosted Jun 11, 2014, 4:59 PM
So you always have to implement indexers in the traditional way.
prashant jadhavPosted Jun 11, 2014, 3:06 PM
VulpesPosted Jun 11, 2014, 11:53 AM
An Employee class is not an ideal candidate for an indexer which is normally used with some sort of collection.
However, suppose each Employee can have up to 5 employments which are stored in an integer array using a company code (starting from 1) for the employer: