prashant jadhav

prashant jadhav

  • NA
  • 24
  • 997

using indexer as automatic implementing properties

Jun 11 2014 10:59 AM

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();
}
}
}
 

Answers (3)