Was delegates static by default?
- by Sri Kumar
Hello All,
I was just trying to understand delegates using the following code.
public class delegatesEx
{
public delegate int Mydelegate(int first, int second);
public int add(int first, int second)
{
return first + second;
}
public int sub(int first, int second)
{
return first - second;
}
}
Here is my main method
Console.WriteLine("******** Delegates ************");
delegatesEx.Mydelegate myAddDelegates = new delegatesEx.Mydelegate(new delegatesEx().add);
int addRes = myAddDelegates(3, 2);
Console.WriteLine("Add :" + addRes);
delegatesEx.Mydelegate mySubDelegates = new delegatesEx.Mydelegate(new delegatesEx().sub);
int subRes = mySubDelegates(3, 2);
Console.WriteLine("Sub :" + subRes);
I didn't declare delegate to be static but i was able to access it using the Class name. How is it possible?