为什么一些字符串函数用“params”声明,其他字符串不是?

编程入门 行业动态 更新时间:2024-10-12 10:26:01
本文介绍了为什么一些字符串函数用“params”声明,其他字符串不是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

没问题,只是一个问题: 您可以写: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.

更多推荐

为什么一些字符串函数用“params”声明,其他字符串不是?

本文发布于:2023-11-30 07:05:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649112.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   函数   声明   params

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!