A delegate is a reference type variable that holds the reference to one or multiple method(s). The reference can be changed at runtime.
public delegate int mdel(int a, int b);
protected void Page_Load(object sender, EventArgs e)
{
mdel del = add;
del += sub;
del += mul;
del -= add;
Response.Write(del(20,10).ToString());
}
public int add(int m, int n)
{
return m + n;
}
public int sub(int m, int n)
{
return m - n;
}
public int mul(int m, int n)
{
return m * n;
}
public delegate int mdel(int a, int b);
protected void Page_Load(object sender, EventArgs e)
{
mdel del = add;
del += sub;
del += mul;
del -= add;
Response.Write(del(20,10).ToString());
}
public int add(int m, int n)
{
return m + n;
}
public int sub(int m, int n)
{
return m - n;
}
public int mul(int m, int n)
{
return m * n;
}
No comments:
Post a Comment