C# method generic params parameter bug?
Posted
by Mike M
on Stack Overflow
See other posts from Stack Overflow
or by Mike M
Published on 2010-05-18T09:37:16Z
Indexed on
2010/05/18
9:40 UTC
Read the original article
Hit count: 284
Hey,
I appears to me as though there is a bug/inconsistency in the C# compiler.
This works fine (first method gets called):
public void SomeMethod(string message, object data); public void SomeMethod(string message, params object[] data); // .... SomeMethod("woohoo", item);
Yet this causes "The call is ambiguous between the following methods" error:
public void SomeMethod(string message, T data); public void SomeMethod(string message, params T[] data); // .... SomeMethod("woohoo", (T)item);
I could just use the dump the first method entirely, but since this is a very performance sensitive library and the first method will be used about 75% of the time, I would rather not always wrap things in an array and instantiate an iterator to go over a foreach if there is only one item.
Splitting into different named methods would be messy at best IMO.
Thoughts?
© Stack Overflow or respective owner