Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // create the test class
            MyClass obj = new MyClass();
            // Connect multiple event handlers
            obj.valueChanged += changeListener1;
            obj.valueChanged += changeListener2;

            // Use an anonymous delegate as the event handler
            obj.valueChanged += delegate(string s) {
                Console.WriteLine("This came from the anonymous handler!");
            };

            obj.objChanged += delegate(object sender, ObjChangeEventArgs e) {
                Console.WriteLine("{0} had the '{1}' property changed", sender.GetType(), e.propChanged);
            };

            string str;
            do {
                Console.WriteLine("Enter a value: ");
                str = Console.ReadLine();
                if (!str.Equals("exit")) {
                    obj.Val = str;
                }
            } while (!str.Equals("exit"));
            Console.WriteLine("Goodbye!");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // create the test class
            MyClass obj = new MyClass();


            obj.objChanged += delegate(object sender, ObjChangeEventArgs e)
            {
                Console.WriteLine("{0} had the '{1}' property changed", sender.GetType(), e.propChanged);
            };


            string str;
            do {
                Console.WriteLine("Enter a value: ");
                str = Console.ReadLine();
                if (!str.Equals("exit")) {
                    obj.Val = str;
                }
            } while (!str.Equals("exit"));
            Console.WriteLine("Goodbye!");
        }