Conditionally allow params on generic parameters if generic type is params eligible #7840
Unanswered
ThadHouse
asked this question in
Language Ideas
Replies: 1 comment 4 replies
-
Why not just add an overload, single parameter version has higher priority new Cup<int>().Add(1); // void Cup<T>.Add(T value)
public class Cup<T> {
public void Add(params T[] value) { Console.Write("from params"); }
public void Add(T value) { Console.Write("from single"); }
} |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Was playing around with some generic code that could take either an array or a base type, and something I was thinking would be cool would be to allow
params
on a non array generic parameter, and only allow the caller to use params if the target type allows params.Something like the following example.
And then you could use this like the following.
Whereas if T wasn't allowed to be params, the call would still work, but just wouldn't work like an array
I know a lot of work to params is being looked at, so maybe this would be cool too.
Beta Was this translation helpful? Give feedback.
All reactions