C# method generic params parameter bug?
- by Mike M
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?