Events in C# are based on delegates, the Originator defining one or more callback functions. A class that wants to use events defines callback functions as delegates and the listening object then implements then.
Source Code:EventTest.csusing System;public class MyEvt{ public delegate void t(Object sender,MyArgs e);// declare a delegate public event t tEvt; //delcares a event for the delegate public void mm(){ //function that will raise the callback MyArgs r=new MyArgs();tEvt(this,r); //calling the client code } public MyEvt(){ }} //arguments for the callbackpublic class MyArgs:EventArgs{public MyArgs(){ }} public class MyEvtClient{ MyEvt oo; public MyEvtClient(){this .oo=new MyEvt(); this .oo.tEvt +=new MyEvt.t(oo_tt);}public static void Main (String [] args){ MyEvtClient cc=new MyEvtClient(); cc.oo.mm();}//this code will be called from the server public void oo_tt(object sender, MyArgs e){ Console.WriteLine("yes"); }}Save the File as EventTest.csCompile C:\>csc EventTest.csrun C:\>EventTest
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: