Public class class1
{
Delegate int deleadd (int A, int B); // delegate statement
Delegate int deleremove ();
Public class1 ()
{
}
Public static void start ()
{
Class1 C1 = new class1 ();
Deleadd add = new deleadd (c1.add); // instantiate the delegate and specify the delegate Method
Add + = new deleadd (c1.add1); // delegate another method
Deleremove remove = NULL;
Remove + = new deleremove (c1.remove); // initialize two methods of delegation (1, new 2, + = new)
Remove + = new deleremove (c1.remove1 );
MessageBox. Show (add (). tostring (); // display 30 (displayed in the Add1 method), display 30 again (returned by the function)
MessageBox. Show (remove (). tostring (); // display "not added", "not added", 100
}
Private int add (int A, int B)
{
Return A + B;
}
Private int Add1 (int A, int B)
{
MessageBox. Show (convert. tostring (a + B ));
Return A + B;
}
Private int remove ()
{
MessageBox. Show ("not added ");
Return 0;
}
Private int remove1 ()
{
MessageBox. Show ("the same is not added ");
Return 100;
}
}
Public class form
{
Class1.start ();
}