This question is related to Why is there a difference in behaviour of an application built in VS 2010 v.s. VS 2012? but in my case I have vs 2010 and 2013 installed (both professional).
According to the answer from the referenced question it is because of the different c# versions. But compiling and running the code from command line :
class Program
{
static void Main(string[] args)
{
var funcs = new List<Func<int>>();
var texts = new [] { 1, 2, 3 };
foreach (var text in texts)
{
funcs.Add(delegate { return text; });
}
for (int i = 0; i < 3; i++)
Console.WriteLine(funcs.ToList()[i]());
Console.ReadKey();
}
}
With csc /out:My.exe /langversion:4 Program.cs gives me the same 1,2,3 output as with /langversion:5 and /langversion:3
Running with vs 2010 with target framework dot net 4 client profile, gives me 3,3,3 Is there something I am missing?