471,627 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Ambiguous Overloads

Hi all,
If I have the following methods:

public void foo(object o)
{
}

public void foo(string s)
{
}

public void foo(array a)
{
}

And I call:
foo(null);

I should (and do) get an ambiguous call error.

But if I comment out the foo(string) or foo(array)

then I do not get the error and it just goes to the not foo(object) one
(ie foo(array)).

Why is this?

JB
Feb 23 '06 #1
2 1283
Maybe this can help you.

http://msdn.microsoft.com/library/de...ec_7_4_2_2.asp

Feb 23 '06 #2
John B <jb******@yahoo.com> wrote:
If I have the following methods:

public void foo(object o)
{
}

public void foo(string s)
{
}

public void foo(array a)
{
}

And I call:
foo(null);

I should (and do) get an ambiguous call error.

But if I comment out the foo(string) or foo(array)

then I do not get the error and it just goes to the not foo(object) one
(ie foo(array)).

Why is this?


Because it picks the most specific one. Array and string aren't more or
less specific than each other, so there's ambiguity - but string is
unambiguously more specific than object (as is Array).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by John M | last post: by
4 posts views Thread by rjd | last post: by
reply views Thread by Michi Henning | last post: by
4 posts views Thread by Chameleon | last post: by
9 posts views Thread by neildferguson | last post: by
3 posts views Thread by i3x171um | last post: by
8 posts views Thread by Anna Smidt | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.