Ejemplo n.º 1
0
 public void Subscribe(ClassWithReturnIntDelegate theClass)
 {
     theClass.returnIntDelegate += delegate {
         Thread.Sleep(1000);
         return(++myCounter);
     };
 }
Ejemplo n.º 2
0
        static void RunDelegateReturnInt()
        {
            ClassWithReturnIntDelegate tmpClass = new ClassWithReturnIntDelegate();

            ClassWithReturnIntDelegate.FirstSubscriber fst = new ClassWithReturnIntDelegate.FirstSubscriber();
            fst.Subscribe(tmpClass);
            ClassWithReturnIntDelegate.SecondSubscriber scd = new ClassWithReturnIntDelegate.SecondSubscriber();
            scd.Subscribe(tmpClass);
            int result = tmpClass.returnIntDelegate();

            Console.WriteLine("result = {0}", result);
            result = tmpClass.returnIntDelegate();
            Console.WriteLine("result = {0}", result);
            result = tmpClass.returnIntDelegate();
            Console.WriteLine("result = {0}", result);

            tmpClass.Run();
        }
Ejemplo n.º 3
0
 public void Subscribe(ClassWithReturnIntDelegate theClass)
 {
     theClass.returnIntDelegate += delegate {
         return(myCounter += 2);
     };
 }