|
||||||
| C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
||||
|
Re: Is this the right use of Delegates of Events ? (short code)
Well, after brief looking at this sub-link I can tell it's correct.
Delegates and Events in C# / .NET
__________________
proudly presenting my personal website and game website: F1Simulation. a thrilling Managed DirectX racing game... also my Ask Me look at my tutorials about cropping images and Mono: bundling Mono with programs and lambda expressions |
|
|||
|
Re: Is this the right use of Delegates of Events ? (short code)
This is an incorrect way of using delegates and events.
your delegate is public! your CreateCarClient could easily invoke the delegate directly for example: publisher.onBadEngineConfig(this, new CreateCarEventArgs()); this is just wrong, you should know better. correct way: define an event: public event EventHandler<CreateCarEventArgs> OnCreateCarEvent; notify registered users Code:
private void NotifyCarEventCreated(OnCreateCarEvent e)
{
if(null != OnCreateCarEvent)
{
OnCreateCarEvent(this, e);
}
}
if you have an instance o34 and you wish to register:
o34.OnCreateCarEvent += new EventHandler<CreateCarEventArgs>(SomeMethod);
private void SomeMethod(object o, CreateCarEventArgs e)
{
}
Last edited by Jaan; 10-01-2009 at 10:06 AM.. Reason: Please use code tags when you are posting your codes ! |
|
||||
|
Re: Is this the right use of Delegates of Events ? (short code)
Mixpage- I had a long break from .NET now so I am not sure of what I want to say, so let me throw the cards and let you figure it out, okay?
I think your code is correct, that is you are using delegate variable. I think you can assign only 1 method to it, no more no less but one. Autoboxing- Events and delegates can be different things. Event variable can hold from none to many delegates assigned. If you invoke it, all of them will be executed. But you can still use delegates as single procedure holders.
__________________
proudly presenting my personal website and game website: F1Simulation. a thrilling Managed DirectX racing game... also my Ask Me look at my tutorials about cropping images and Mono: bundling Mono with programs and lambda expressions |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| F# First Class Events – Async Workflows + Events Part II | Kernel | News | 0 | 09-02-2009 08:40 PM |
| F# First Class Events – Creating Events | Kernel | News | 0 | 08-18-2009 01:50 AM |
| The spirit of MVVM (ViewModel), it’s not a code counting exercise. | Kernel | News | 1 | 08-03-2009 02:19 PM |
| Back to Basics: Delegates, Anonymous Methods and Lambda Expressions | Kernel | News | 0 | 11-27-2008 02:30 PM |
All times are GMT -5. The time now is 09:40 AM.
Amrosama.cc
Arekbulski.cc
Debtboy.cc
Guest.cc
Jaan.cc
James.cc
Mathx.cc
Tsz.cc
Vswe.cc