Thursday, October 28, 2010

Interesting StackOverflow Exception in C#

class Program
{
  public static void Main(string[] args)
  {
    Program p = new Program();
    p.Krishna = 10;
  }

  private int krishna;
  public int Krishna
  {
    get
    {
      return krishna;
    }
    set
    {
      Krishna = value;
    }
  }
}

In the set block, change from Krishna to krishna, and the stack overflow exception will go away.

No comments:

Post a Comment