没问题,只是一个问题: 您可以写:trimmed = untrimmed.Trim('(',')','[',' ]'); 但你不能写:pos = line.IndexOfAny('(',')','[',']'); ...'trimChars'是'params char []','anyOf'是'char []'(没有'params')。你必须写:pos = line.IndexOfAny(new char [] {'(',')','[',']')}; 是有没有合理的理由为什么'anyOf'不是'params'? 我的第一个想法是它可能会导致重载过多,因为在a之后不再允许参数'PARAMS'。存在IndexOfAny重载,参数尾随'anyOf'。也许这会让编译器感到困惑。 编号String.Split()有一个'params char []'重载,其他有附加参数(但对于那些,'对于第一个'separator'参数,省略了params'。如果编译器可以处理Split(),为什么它不能处理IndexOfAny()和LastIndexOfAny()的相同构造? 程序员是否忘记了params,还是有理性/技术原因? 我尝试了什么: 提到的功能声明在VS.元数据显示中可用。
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.
推荐答案引用:
为什么'anyOf'不是'params'有什么理由吗?
Is there any rational reason why 'anyOf' is not a 'params'?
可能,但微软将是唯一真正了解的人。您可以在文档页面上添加反馈,或查看MSDN上的语言论坛。毕竟,他们是专家。
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.