Monday, 4 March 2013

How to call event of interface



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

  public delegate void xyz(string str);
   public class Test
   {
       public event xyz Notify;

       public void NotifyNow()
       {
           OnNotify();
       }

       void OnNotify()
       {
           if (Notify != null) Notify("amit");
       }
   }
    class Program
    {
        static void Main()
        {
            Test test = new Test();
            test.Notify += new xyz(test_Notify);
            test.NotifyNow();         
            Console.ReadLine();
        }

        static void test_Notify(string str)
        {
            Console.WriteLine("Notified xyz---" + str);
        }
    }

No comments:

Post a Comment