Was delegates static by default?
Posted
by Sri Kumar
on Stack Overflow
See other posts from Stack Overflow
or by Sri Kumar
Published on 2010-04-14T07:03:06Z
Indexed on
2010/04/14
7:23 UTC
Read the original article
Hit count: 255
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?
© Stack Overflow or respective owner