-
Notifications
You must be signed in to change notification settings - Fork 1k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
params TCollection<T> #2141
Comments
How would you create a params of an interface. Specifically IEnumerable? |
@YairHalberstadt Because interfaces are not types, you cannot create them. This is no different than everywhere else in the framework. That's why you specifically provide a concrete type that implements your ideal preference of IEnumerable. So, depending on your situation, you might want to do any of the following:
In all three of those situations, |
@TonyValenti That would be the advantage of allowing params IEnumerable instead. I do like your proposal, and I think it is probably better than allowing IEnumerable params, I'm just raising a potential limitation with it. |
A method shouldn't dictate the concrete type of parameters that it is using though beyond what is necessary to implement the algorithm that the method is encapsulating. And that encapsulation never includes the construction of the parameter because that happens outside of the method call. |
Meh That's more of a heuristic than a hard and fast rule. Over here I think there is very little harm that would cause, and the benefit outways any code purity concerns I have. |
@bbarry, while I do agree with you, @YairHalberstadt If I have:
I should still be able to call it using any of the following methods:
I do suppose that it could be agreed that something like:
Would result in a call-site transformation to List if the 'params' items are listed.
|
Also not that However I don't think that's a genuine issue, as it's already special cased for collection initialisers. |
Also linking #179 which has a link to a proposal for a builder pattern to construct |
It gets a bit verbose, but the
That would allow you to pick the most efficient enumerable type for your particular algorithm rather than always using the same default. Users could even consider that as a useful hint on which type works best with your method in case they are constructing their own collection. |
What collection would be more efficient than an array? Per #179 that's what the client would generate. Your suggestion would make the feature vastly more complicated and I don't see any benefit to it. |
Converting to a discussion. This should be considered as part of #179. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi All,
I've seen different requests for params IEnumerable and such and I had a though I wanted to share.
Right now params requires a single dimension array. What if Params would allow any type with a default constructor and collection initializer method/extension methods?
Could be transformed by the compiler into:
This would basically give people the ability to determine the type of params they want. LinkedList, List, HashSet, etc.
#1366
#619
#1757
#178
The text was updated successfully, but these errors were encountered: