C# Behind the scenes – Local Functions

The second “Behind the scenes” article, will be about local function.

This is much simple from previous post about yield keyword.
In short, local function translated to a method of the class.

Example 1

void M(int o)
{
    int Multiply(int n) => n * 2;

    foreach (var i in new List<int> { 1, 2, 3, 4, 5 })
    {
        Console.WriteLine(Multiply(i));
    }
}

Continue reading

Posted in .NET, c# | Tagged , , , | 1 Comment