Consider this code:
private static int i = 0;
static void Main(string[] args)
{
DoSomething();
Console.ReadLine();
}
public static void DoSomething()
{
Console.WriteLine(i);
++i;
DoSomething();
}
Each time I run it, I get StackOverflowException on a different value of i variable. For example 16023, 16200, 16071.
What's the reason behind this? Is it a bug in C# compiler?