C# 3.0's argumentless lambda

13 March 2008 | Scott Williams | .NET 3.5, C#, lambdas

One of the hip new features of C# 3.0 is the built in support for lambdas:

Func<int> sq = x => x * x;
sq(5); // equals 25

This is very fancy, but sometimes you need to perform a lambda that has no argument. The syntax for that is simply "()".

Func<object> doStuff = () => Console.WriteLine("stuff has been done");
doStuff();

Comments are closed.