C# notation understanding Select(int.Parse)

I found a little script that I understand fully. I've got a string with "1 -2 5 40" for example. It reads the input string, splits it into a temporary array. Then this array is parsed and each element is transformed into an integer. The whole thing is order to give the nearest integer to zero.

But what I don't understand is the notation Select(int.Parse). There is no lambda expression here and the method int.Parse isn't called with brackets. Same with the OrderBy(Math.Abs)

Thank you in advance =)

var temps = Console.ReadLine().Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);  

var result = temps.Select(int.Parse)
.OrderBy(Math.Abs)
.ThenByDescending(x => x)
.FirstOrDefault();
Jon Skeet
people
quotationmark

int.Parse is a method group - what you're seeing is a method group conversion to a delegate. To see it without LINQ:

Func<string, int> parser = int.Parse;
int x = parser("10"); // x=10

It's mostly equivalent to:

Func<string, int> parser = text => int.Parse(text);

... although there are plenty of differences if you want to go into the details :)

people

See more on this question at Stackoverflow