What is delegates in C# ? Advantages of Delegates in C#. code example
Example 1: delegates in c#
using System;
using System.IO;
class Delegate
{
public delegate void HelloMethod(string str);
public static void Main(String [] args)
{
HelloMethod delegateInstance = new HelloMethod(print);
delegateInstance("Hey there! Iam delegate method");
}
public static void print(string delegateStr)
{
Console.WriteLine(delegateStr);
}
}
Example 2: what are delegates and how to use them c#
MyDelegate d = new MyDelegate(ShowText);