ForEach extension method

c#, linq

Solution

There is an implicit conversion from a method group (`Console.WriteLine` in this case) and a compatible delegate type. You code is effectively the same as

Action<int> f = Console.WriteLine;
Enumerable.Range(1,10).ToList().ForEach(f);

The delegate `f` is compatible with the method `void Console.WriteLine(int)`

Problem

I'm a bit confused over a line of code: ``` Enumerable.Range(1,10).ToList().ForEach(Console.WriteLine); ``` This line does what it says it does, it prints out each number from 1 to 10 with a line break inbetween each of them, all that with one neat little line of code.. Now I'm only a C# novice at best, but it looks completely foreign to me, how can we call `Console.WriteLine()` without providing it with any arguments? How does it know what it's going to print? From this syntax it's not even clear to me that we're calling on a method (considering the lack of paranthesis around `WriteLine`). I'm assuming that there's a lot of stuff going on "behind the scenes" here but I'm not very good at reading IL code, from what I've gathered reading the MSIL it seems like `ForEach` calls a generic delegate(`System.Action`) on each element in the collection, I am guessing that it then passes the element as an argument to the `System.Action` delegate but that's only my guess..

Original source