Click here to Skip to main content
15,442,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Not a problem, just a question:

You may write: trimmed = untrimmed.Trim('(', ')', '[', ']');
But you can't write: pos = line.IndexOfAny('(', ')', '[', ']');

... 'trimChars' is a 'params char[]', 'anyOf' is a 'char[]' (without 'params'). You must write: pos = line.IndexOfAny(new char[] {'(', ')', '[', ']')};

Is there any rational reason why 'anyOf' is not a 'params'?

My first thought was that it might mess up overloading, since no more parameters are allowed after a 'params'. There are IndexOfAny overloads with parameters trailing 'anyOf'. Maybe this would confuse the compiler.

No. String.Split() has one 'params char[]' overload, others with additional parameters (but for those, 'params' is omitted for the first, 'separator', parameter). If the compiler can handle Split(), why couldn't it handle the same constructions for IndexOfAny() and LastIndexOfAny()?

Did the programmer just forget about params, or is there a rational/technical reason?

What I have tried:

Function declarations mentioned are available in the metadata display in VS.
Posted
Updated 3-Dec-18 23:50pm

1 solution

Quote:
Is there any rational reason why 'anyOf' is not a 'params'?
Possibly, but Microsoft will be the only people who really know. You can add feedback on the documentation pages, or check the language forums at MSDN. After all, they are the experts.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900