Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undocumented overload of 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();

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.

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.

EDIT: as shown above, it splits on whitespace.

like image 584
Neil N Avatar asked May 25 '10 16:05

Neil N


1 Answers

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();

Is the same as:

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

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.

like image 172
driis Avatar answered Oct 12 '22 11:10

driis