I use the .NET 4 (not .NET 4.5 or any other version of the framework!)
Why different versions of Visual Studio will output different result of the same code using the SAME .NET Framework?
I have the following
static void Main(string[] args)
{
var values = new List<int>() { 1, 2, 3, 4, 5 };
var funcs = new List<Func<int>>();
foreach (var v in values) {
funcs.Add(() => v * 10);
}
foreach (var f in funcs) {
Console.WriteLine(f());
}
Console.ReadKey();
}
In Visual Studio 2013 the output is 10 20 30 40 50
(Target .NET v == 4).
In Visual Studio 2010 the output is 50 50 50 50 50
(Target .NET v == 4).
Where is the problem? How to identify the C# (not the .NET!) version used by each Studio
for the .NET 4
C:\Windows\Microsoft.NET\Framework\v4.0.30319>csc /?
Microsoft (R) Visual C# Compiler version 4.0.30319.33440
for Microsoft (R) .NET Framework 4.5C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>csc /?
Microsoft (R) Visual C# Compiler version 4.0.30319.33440
for Microsoft (R) .NET Framework 4.5C:\Program Files (x86)\Microsoft Visual Studio 12.0>csc /?
Microsoft (R) Visual C# Compiler version 12.0.30110.0
for C# 5
EDIT
Can I say that
VS 2010 == C# 4
VS 2013 == C# 5
and this independently of the target framework of the concrete solution?