Thread: C#, Making Events?

  1. #1
    #junkie
    Join Date
    Oct 2004
    Posts
    240

    C#, Making Events?

    Ok, i need to do one of two things.

    1.) Make my own event system. I have a "Wrapper" that holds some TCP data in it. It has events and whatnot already inside of it, how can i give my class the ability to use events to trigger defined functions outside of the Wrapper Class?

    2.) Just as the same as the first one, but im just looking at it dif. Is it possible to "assign" a function to a class? In otherwords, give the class a "function variable", where it holds a reference to a function. When you run the class you give that reference variable a function you want to be triggered, and all is well..


    So ya.. im just trying to figure how to make an event based class, as it is important to my code.

    Any help would be awesome, thanks!
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    You can do both.

    You can have events in a class that you can fire and hope someone is attached to it Or you can have an explicit function pointer where you can call one function.

    Look up the delegate keyword. You can declare a delegate which is a definition of a function. You can then save functions in a variable of that type and call them.

    You can also have events that are declared to be of a type of one of your delegates. Other classes can then consume these events.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  2. seismic events program
    By santaclaus in forum C Programming
    Replies: 16
    Last Post: 11-23-2003, 03:23 PM
  3. Replies: 2
    Last Post: 01-13-2003, 01:28 PM
  4. ATL: fireing events from a Instanced object
    By CHECCO in forum C++ Programming
    Replies: 2
    Last Post: 09-03-2002, 07:05 AM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM