Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

ok,i got the idea of delegates,which are pointers to methods\functions...

but whay do i need events???? i mean i cant unerstand it that good...any idea how do understand it?????

 

looks on google...read msdn,and alot of more tutorials,but most of them arent that clear and understandable... :o :confused:

Posted

Hope this helps

 

ok,i got the idea of delegates,which are pointers to methods\functions...

but whay do i need events???? i mean i cant unerstand it that good...any idea how do understand it?????

 

looks on google...read msdn,and alot of more tutorials,but most of them arent that clear and understandable... :o :confused:

You dont "need" events, there are *always* (until someone gives me an example otherwise (not including the events allready there)) ways of coding to avoid needing events.. However they are very usefull especially when writing class's that other people will be using. Say you have a class and something important happens with varying frequency, maybe the program may have to react maybe it wont, with events you dont have to worry about whether its needed or not... Code example (because my writen descriptions suck).

/* Without Events */
//inside the dll
class MYCLASS
{
    int X;
    public virtual int x{
        get{return 1;}
        set{X = value;}
    }
}
////the dll users code
class fMYCLASS : MYCLASS
{
  override int x{
      get{
        someonewaslookingatx();
        return X;
       }
      set{
       someonechangedthevalueofx();
      X=value;
      }
    }
     void someonewaslookingatx(){...}
     void someonechangedthevalueofx(){...}
}
//With Events
//Dll Code
class MYCLASS
{
    int X;
    public delegate void PointlessEvent();
    public event PointlessEvent xget;
    public event PointlessEvent xset;
    public int x{get{if(xget!=null)xget();return X;}
       set{if(xset!=null)xset();return X;}
      }
}
//thier code no inherited class they can just classinstance.xget += new EventHandler(functionname)....

as you can see there is no need for a inheriting class with events, this style of solution can be used much better than shown but hopefully you get the idea.

Posted

'event' is a decoration to a delegate declaration.

 

Among other things, decorating a delegate field with event allows for multiple functions to be executed as a result of the event being fired.

 

 

Get Programming .NET Components (O'Reilly [4/2003], Lowy, ISBN:0596003471)

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

AWESOM!!!! thank you very much!!!!!! ;)

 

eventually i dont think i gonna use events that much,i dont see (..yet) any use for them,that i cant do with delegates.

basically both of them (events and delegates) are method\indexers .... pointers..(am i right??) :confused:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...