Tip #006
Chain lambdas on one delegate
About this tip
Delegates are multicast: += chains lambdas and one call runs them all, in order. It is available since C# 3. The key line is hello += () => Console.Write("World, ") in lambdas.cs. Run it and the output reads Hello World, .NET & Khalid.
Learn more
Did this tip save you some time? Consider buying me a coffee to fuel the next one.
Buy me a coffeeCode
Action hello = () => Console.Write("Hello ");hello += () => Console.Write("World, ");hello += () => Console.WriteLine(".NET & Khalid");hello();Output
$ dotnet run lambdas.csHello World, .NET & Khalid