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 / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

"Overloading" delegate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul Selormey - 06 Sep 2004 06:50 GMT
Hello,
What is the best way to have something like this?

protected delegate string CalculationDelegate(int count);
protected delegate string CalculationDelegate(double count);

Best regards,
Paul.
Peter Rilling - 06 Sep 2004 09:54 GMT
Could you just have one delegate that uses a double since an integer can be
cast into a double with no loss of precision?

> Hello,
> What is the best way to have something like this?
[quoted text clipped - 4 lines]
> Best regards,
> Paul.
Paul Selormey - 06 Sep 2004 10:04 GMT
Thanks for the response, and the nice thought.
The posted code was just for illustration, it is not
the real thing I wish to do.

Best regards,
Paul.

> Could you just have one delegate that uses a double since an integer can be
> cast into a double with no loss of precision?
[quoted text clipped - 7 lines]
> > Best regards,
> > Paul.
Chuck - 07 Sep 2004 19:30 GMT
I am assuming you are coding in C#.

If you want to avoid explicit overloading of the delegate than your
parameter of one type has to implicitly or explicitly convert to the type of
the delegate parameter.
If the parameter is a built-in then try using Convert. for explicit
conversion.
If the parameter objects are yours, then they have to be in an inheritance
relationship (the parameter will be the superclass) or implement the same
interface (the parameter will be the interface).  Inside the implementation
of the handler you can query the objects type ( obj is typeof(xxx) )  and on
true cast the parameter to the correct type (xxx) and do your activities.
Do this for each possible type and throw an exception if there isn't a match
('else throw new NotImplementedException(...)' ) .   (This will keep your
code honest).

This worked for me.

Chuck

> Hello,
> What is the best way to have something like this?
[quoted text clipped - 4 lines]
> Best regards,
> Paul.

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.