Create new Console application in Visual Studio and run with F5 , Step down by clicking on the main method press F9 to set break point and run by F5 again and F11 for each step ...
SOURCE:
using System;
namespace ControlsBook2.Ch05
{
delegate void SimpleMulticastDelegate(int a);
public class DelegateImplementorClass
{
public void ClassMethod(int i)
{
Console.WriteLine("You passed in " + i.ToString() + " to the class method");
}
static public void StaticClassMethod(int j)
{
Console.WriteLine("You passed in " + j.ToString() +
" to the static class method");
}
public void YetAnotherClassMethod(int k)
{
Console.WriteLine("You passed in " + k.ToString() +
" to yet another class method");
}
}
class Program
{
static void Main(string[] args)
{
DelegateImplementorClass ImpClass = new DelegateImplementorClass();
SimpleMulticastDelegate d = new SimpleMulticastDelegate(ImpClass.ClassMethod);
d(5);
Console.WriteLine("");
d += new SimpleMulticastDelegate(DelegateImplementorClass.StaticClassMethod);
d(10);
Console.WriteLine("");
d += new SimpleMulticastDelegate(ImpClass.YetAnotherClassMethod);
d(15);
Console.WriteLine ( "NOW START REMOVING" );
d -= new SimpleMulticastDelegate ( DelegateImplementorClass.StaticClassMethod );
d ( 35 );
Console.WriteLine ( "" );
Console.Read();
}
}
}
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!