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);
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter