We can use delegate as a type for method parameter.
using System;
delegate void Printer(int i);
class Test
{
static void consolePrinter(int i)
{
Console.WriteLine(i);
}
static void output(int[] intArray, Printer p)
{
foreach (int i in intArray)
{
p(i);
}
}
static void Main()
{
Printer p = consolePrinter;
int[] intArray = new int[] { 1, 2, 3 };
output(intArray, p);
}
}
The output:
1
2
3