I've just read this question: Convert string[] to int[] in one line of code using LINQ
There was an array of strings:
var arr = new string[] { "1", "2", "3", "4" };
And one of the accepted answers was:
int[] myInts = arr.Select(int.Parse).ToArray();
I tried it myself and received a cs04011 compiler error:
string str = "4 8 15 16 23 42";
int[] intArray = str.Split(' ').Select(int.Parse).ToArray();
Here's page, describing this compiler error: MSDN
If I do it this way, it works fine:
int[] intArray = str.Split(' ').Select(p=>int.Parse(p)).ToArray();
I'm wondering, why did the accepted asnwer for the previous question worked fine and I get an error?
My guess is that my visual studio (2008 express, targeted framework = 3.5) is no good, but I failed to find any proofs.
Thanks in advance!
The short answer is: C# type inference and support for method group conversions has improved over time. You're still using the C# 3 compiler (which is what shipped in VS 2008). The exact details are tricky, and I can never remember exactly what changed in the specification - type inference is one of the hairier bits of the spec, and it doesn't quite describe the intended behaviour quite correctly anyway, as far as I'm aware.
If you use a more recent compiler following more recent language rules, it'll be fine. This doesn't depend on the version of the framework you're targeting - only the compiler/language version is relevant here.
I'd strongly recommend upgrading straight to Visual Studio 2015 - C# 6 has some lovely features for removing cruft from your code...
See more on this question at Stackoverflow