Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

fire events in derived class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
parez - 28 Mar 2008 16:23 GMT
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?
Jon Skeet [C# MVP] - 28 Mar 2008 16:34 GMT
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

parez - 28 Mar 2008 16:44 GMT
> > whats the best way of firing events  in derived class?
> > expose a protected function in base class which fires the event?
[quoted text clipped - 11 lines]
> Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk

am using .net 3.0  vs2008
Jon Skeet [C# MVP] - 28 Mar 2008 16:50 GMT
> > 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

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

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

parez - 28 Mar 2008 17:03 GMT
> > > Which version of the framework are you using? If you can get away
> > > without declaring your own delegate type, e.g. using EventHandler<T>,
[quoted text clipped - 8 lines]
> Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk

That worked.. thanks
What if i was using an older version.. then where would i put the
delegates?
Jon Skeet [C# MVP] - 28 Mar 2008 17:10 GMT
<snip>

> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Ignacio Machin ( .NET/ C# MVP ) - 28 Mar 2008 20:09 GMT
> > > > Which version of the framework are you using? If you can get away
> > > > without declaring your own delegate type, e.g. using EventHandler<T>,
[quoted text clipped - 12 lines]
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.