This is example is used for mapped both
the static and instance methods in the Delegates
using ASP.Net C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Delegates
{
delegate void MyDelegate();
public class MyClass
{
public void InstanceMethods()
{
Console.WriteLine("Instance method call");
}
static public void StaticMethods()
{
Console.WriteLine("Static method call");
}
}
public class MyMainClass
{
static public void Main()
{
MyClass MCObj = new MyClass();
// Delegate Map to the instance method
MyDelegate myDelInstObj = new MyDelegate(MCObj.InstanceMethods);
myDelInstObj();
// Delegate Map to the static method:
myDelInstObj = new MyDelegate(MyClass.StaticMethods);
myDelInstObj();
Console.Read();
}
}
}
I hope it is helpful to you! Thank you!