Replies: 5 comments
-
I'm not yet a fan of the double- |
Beta Was this translation helpful? Give feedback.
-
I sort of feel like the Nonetheless, I feel your pain and ended up writing using static System.StringSplitOptions;
static string[] SplitRemoveEmpty(this string value, char seperator, params char[] seperators) =>
value.Split(seperators.Prepend(seperator).ToArray(), RemoveEmptyEntries);
static string[] SplitRemoveEmpty(this string value, string seperator, params string[] seperators) =>
value.Split(seperators.Prepend(seperator).ToArray(), RemoveEmptyEntries); a long time ago. |
Beta Was this translation helpful? Give feedback.
-
That might make a good API proposal for corefx. Allocating an array for the most common case of |
Beta Was this translation helpful? Give feedback.
-
@alrz you're absolutely right, those implementations are suboptimal. Thanks for the suggestion about making a corefx proposal, I may well now do just that. |
Beta Was this translation helpful? Give feedback.
-
@aluanhaddad good idea. However, I think there are some scenarios like: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In C# we have currently a rule
A params parameter must be the last parameter in a formal parameter list
. I think it's too severe because it limits several cases even in standard library.For example,
string.Split
method is declared like:public string[] Split(char[] separator, StringSplitOptions options)
But it could be much more useful if it's declared like:
public string[] Split(params char[] separator, StringSplitOptions options)
But here we encounter with a problem that params cannot be non-last argument.
Proposal
Allow multiple params and params as non-last argument until they can be treated ambiguously, e.g.
Beta Was this translation helpful? Give feedback.
All reactions