Events in C #

Source: Internet
Author: User

usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.IO;namespacecodetest{classProgram {Static voidMain (string[] args) {eventtest e=NewEventtest (Ten); E.enumdelegate+=NewcodeTest.EventTest.NumDelegate (e.show); E.enumdelegate+ = (x) + = {Console.WriteLine ("anonymous functions can be directly bound! ");            }; E.setvalue ( -); IEvent IE=NewMyClass (); Ie.mydelegate+=Newmydelegate (show); Ie.            Show (); Ie.myeventhandler+=NewEventHandler (Show); Ie.myeventhandler (New Object(),NewEventArgs ());        Console.ReadLine (); }        Static voidShow () {Console.WriteLine ("Show!!!"); }        Static voidShow (Objectsender, EventArgs e) {Console.WriteLine ("Show EventHandler"); }    }    classEventtest {intvalue;  Public Delegate voidNumdelegate (intnum);  Public Eventnumdelegate enumdelegate;  PublicEventtest (intnum)        {SetValue (num); }         Public voidOnnumchange (intnum) {            if(Enumdelegate! =NULL) {enumdelegate (num); }            Else{Console.WriteLine ("Event is null"); }        }         Public voidSetValue (intN) {if(Value! =N) {value=N;            Onnumchange (n); }        }         Public voidShow (intnum) {Console.WriteLine (string. Format ("Num is {0}", num)); }    }     Public Delegate voidMyDelegate ();  Public InterfaceIEvent {//Microsoft recommended wordingEventHandler MyEventHandler {Get;Set; } EventMyDelegate mydelegate; voidShow (); }     Public classmyclass:ievent { PublicEventHandler MyEventHandler {Get;Set; }  Public EventMyDelegate mydelegate;  Public voidShow () {if(MyDelegate! =NULL) MyDelegate (); }    }}

Events in C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.