Pass a Function as a Parameter in C# using Func delegate | Delft Stack

PHOTO EMBED

Sun Sep 19 2021 18:27:20 GMT+0000 (UTC)

Saved by @dejohnny #c

using System;

namespace pass_function_as_parameter
{
    class Program
    {
        static int functionToPass(int x)
        {
            return x + 10;
        }
        static void function(Func<int, int> functionToPass)
        {
            int i = functionToPass(22);
            Console.WriteLine("i = {0}", i);
        }
        static void Main(string[] args)
        {
            function(functionToPass);
        }
    }
}
content_copyCOPY

https://www.delftstack.com/howto/csharp/pass-function-as-parameter-inside-another-function-in-csharp/