fire events in derived class

P

parez

whats the best way of firing events in derived class?
expose a protected function in base class which fires the event?

Also
where should i declare the delegate? same file as the base class?
 
J

Jon Skeet [C# MVP]

parez said:
whats the best way of firing events in derived class?
expose a protected function in base class which fires the event?

That's certainly the conventional way of doing it, yes.
Also
where should i declare the delegate? same file as the base class?

Which version of the framework are you using? If you can get away
without declaring your own delegate type, e.g. using EventHandler<T>,
that would be for the best.
 
P

parez

That's certainly the conventional way of doing it, yes.


Which version of the framework are you using? If you can get away
without declaring your own delegate type, e.g. using EventHandler<T>,
that would be for the best.

am using .net 3.0 vs2008
 
P

parez

In that case I'd use EventHandler<T>, declaring your own EventArgs
subclasses where you need to.

That worked.. thanks
What if i was using an older version.. then where would i put the
delegates?
 
J

Jon Skeet [C# MVP]

That worked.. thanks
What if i was using an older version.. then where would i put the
delegates?

Personally, I tend to like having a file called Delegates.cs with all
the delegates for the namespace. It means it's one place to find them,
and they're neither cluttering up other files, nor taking up a whole
file for a single signature. It's entirely up to you though.

If the delegate is only going to be used by a single type, you could
nest it within that type, if you want.
 
I

Ignacio Machin ( .NET/ C# MVP )

That worked.. thanks
What if i was using an older version.. then where would i put the
delegates?

Hi,

If using version 1.1 (NOTE that if using 2.0 you can still use
EventArgs<T>) you need to declare the delegate explicitely.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top