You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I frequently have to write functions such as the following:
public void Foo(params string[] p) {
Foo((IList<string>)p);
}
public void Foo(IList<string> p) {
// ...
}
It would be nice if I could just do:
public void Foo(params IList<string> p) {
// ...
}
and this would effectively be the same as the first two functions above, i.e. I could pass in an string[], List, or "abc", "def", "123".
This would also make some bugs less likely. For example, if you have:
public void Foo<T>(params T[] p) {
Foo((IList<T>)p);
}
public void Foo<T>(IList<T> p) {
// ...
}
And you do this:
List<int> list = new List<int>();
Foo(list);
This will (unexpectedly) call the first overload with params T[], making the List the first element of an array of . If the first overload didn't exist, then Foo(list) would call the second overload as expected.
If you could just define:
public void Foo<T>(params IList<T> p) {
// ...
}
Then Foo(list) would do the expected thing.
The text was updated successfully, but these errors were encountered:
Yes, if we do #36 we would make it work for any type for which there is an implicit reference conversion from the array type. Thus this would work as a side-effect of #36.
My immediate reaction to this suggestion was "why IList<T>, why not IEnumerable<T>?". Good to see #36 has that covered and that it's something that might really happen.
I frequently have to write functions such as the following:
It would be nice if I could just do:
and this would effectively be the same as the first two functions above, i.e. I could pass in an string[], List, or "abc", "def", "123".
This would also make some bugs less likely. For example, if you have:
And you do this:
This will (unexpectedly) call the first overload with params T[], making the List the first element of an array of . If the first overload didn't exist, then Foo(list) would call the second overload as expected.
If you could just define:
Then Foo(list) would do the expected thing.
The text was updated successfully, but these errors were encountered: