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.