本文介绍了未记录的string.Split()重载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Intellisense和关于string.Split的MSDN文档,没有string.Split的无参数重载.但是如果我输入

According to both Intellisense and MSDN doc on string.Split, there are no parameterless overloads of string.Split. Yet if I type in

string[] foo = bar.Split();

它会编译.而且有效.我已经在Visual Studio 2008和2010中对此进行了验证.在两种情况下,intellisense都不会显示无参数重载.

It compiles. And it works. I have verified this in both Visual Studio 2008 and 2010. In both cases intellisense does not show the parameterless overload.

这是有原因的吗? MSDN/Intellisense文档是否还有其他丢失的重载?通常,我会最好地确定使用intellisense中的重载来浏览的方式.我讨厌认为我在整个.Net框架中都缺少其他可用的选项.

Is there a reason for this? Are there any other missing overloads from the MSDN/Intellisense docs? Usually browsing through overloads in intellisense is how I best determine which overload to use. I'd hate to think I am missing other available options throughout the .Net framework.

如上所示,它在空白处分割.

as shown above, it splits on whitespace.

推荐答案

这是因为Split具有参数重载.不提供参数与提供空数组相同.换句话说,您正在呼叫此重载.

That is because Split has a params overload. Giving no parameters is the same as giving an empty array. In other words, you are calling this overload.

"some text".Split();

与以下相同:

"some text".Split(new char[0]);

此处是有关params关键字的文档.您可能知道,它用于为方法提供可变数量的参数.该数字可能为零.

Here is the documentation on the params keyword. As you probably know, it is used for giving a method a variable number of parameters. That number may be zero.

这篇关于未记录的string.Split()重载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:13