How to use an anonymous function in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main()
    {
        // Anonymous function (lambda) that takes two integers and returns their sum.
        // (a, b) => a + b   ← this is C#'s concise lambda syntax.
        Func<int, int, int> add = (a, b) => a + b;

        // Use the anonymous function
        int result = add(10, 20);

        Console.WriteLine(result);
    }
}


/*
run:

30

*/

 



answered 14 hours ago by avibootz
...