Execute lambda expression immediately after its definition?

c#, lambda

Solution

Sure.

new Action(() => { Console.WriteLine("Hello World"); })();

That should do the trick.

Problem

Is there a way to execute a lambda expression immediately after its definition? In other words (Invalid C# code): ``` (() => { Console.WriteLine("Hello World"); }).Invoke(); ```

Original source