Hi,
Did you try to compile it?
It gives an error "Type 'foo' already defines a member called 'f' with the
same parameter types" which says basically that you need to have a
difference in parameters set between the methods.
> Can I create a specialized generic method depends on the constraint on
> the generic type constraint? such as:
[quoted text clipped - 6 lines]
>
> Thanks.

Signature
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
My interest - 03 Jan 2008 17:54 GMT
Yes, I know the compiler will generate this error message. What I try
to ask is how can I get around with this if I want different f() being
called for different type of parameter (e.g. overloading) .. by
putting a where constraint.
For example, in a non-generic world, this is valid:
static class foo
{
public static void f(double dummy) { ....}
public static void f(Array dummy) { ....}
}
Can I do sth similar in the generic world? I guess one way is just to
create one f() and do dispatch inside the code by checking
tyeof(dummy), but it will be very messy / inconvenient. So I am
trying to seek an alternatively approach.
Jon Skeet [C# MVP] - 03 Jan 2008 18:12 GMT
> Yes, I know the compiler will generate this error message. What I try
> to ask is how can I get around with this if I want different f() being
[quoted text clipped - 13 lines]
> tyeof(dummy), but it will be very messy / inconvenient. So I am
> trying to seek an alternatively approach.
No, you can't overload by type constraints (which is effectively what
you're trying to do).

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