Because int is also a T, it seems this is an ambiguity.

Out of curiosity, is there a rule in C# that says it always chooses the most specific method when using overloads (I can foresee some problems when defining that "most specific" though...)

Kurt

By on 5/16/2008 12:57 PM ()

> Out of curiosity, is there a rule in C# that says it always chooses the most specific method when using overloads

I think there might be, at least that's what C# does. And F# does it as well - in these examples, the distinction works correctly. In the C# class:

public void Reply2(string arg1, ref int arg2) {
Console.WriteLine( "statically typed version");
}

public void Reply2<T>(string arg1, ref T arg2) {
Console.WriteLine( "generic version");
}

public void Reply3(int arg1, ref int arg2) {
Console.WriteLine("statically typed version");
}

public void Reply3<T>(T arg1, ref T arg2) {
Console.WriteLine("generic version");
}

And in F#:

let aval = 10
testclass.Reply2("blah", ref aval)
testclass.Reply3(10, ref aval);

Both of these result in the output "statically typed version".

I have no idea in which significant way the other example is different from those working cases.

By on 5/16/2008 1:52 PM ()

I have no idea in which significant way the other example is different from those working cases.

The fact that you're calling it on a base class may add extra concerns to the mix.

By the way, in your constructor you are comparing var to zero. I think you mean assigment.

Kurt

By on 5/18/2008 1:25 AM ()

The fact that you're calling it on a base class may add extra concerns to the mix.

That is something that came to my mind as well, but in tests it doesn't seem to be the reason, since there are enough working cases that use base class methods as well.

Now, I've found a workaround for this with help from Brian McNamara. It's documented on my blog at [link:www.sturmnet.org]

I still regard this a bug really - there doesn't seem to be any explanation for the behavior I'm seeing and Brian hasn't come up with anything either.

By the way, in your constructor you are comparing var to zero. I think you mean assigment.

Surprising as it may seem, that is actually an assignment. For this first-time initialization enforced by the compiler, one has to use = to assign the value, not <-. Weird, isn't it?

Oliver

By on 5/19/2008 1:25 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper