string emptyString = string.Empty; char[] emptyStringCharArr = emptyString.ToCharArray();
This will give you an empty array of characters. This is because String is already an array of characters in memory, and String.Empty does not matter.
To break it down further, consider implementing .ToCharArray ()
private Char[] toCharArray(String value) { var stringLength = value.Length; var returningArray = new char[stringLength]; for(var i = 0; i < stringLength; i++) { returningArray[i] = value[i]; } return returningArray; }
The length of the course will be zero, and you will return an empty char array. Of course, this is not an exact implementation, but you can see how and why it does not return anything (and therefore does not break into a string, as you expect)
It is not an array with a single String.Empty element, because it does not make sense. When you try to split into an empty array, it does not know how and why you need to split, so the original string is returned to you.
As for why it returns 0 by default, consider:
private int IndexOf(String value, String searchFor) { for(var i = 0; i < value.Length; i++) { if(value.Substring(i, searchFor.Length) == searchFor) { return i; } } return -1; } private int LastIndexOf(String value, String searchFor) { var searchLength = searchFor.Length; for(var i = value.Length - searchFor.Length; i >= 0; i--) { if(value.Substring(i, searchLength) == searchFor) return i; } return -1; }
String.SubString (x, 0) will ALWAYS return String.Empty, regardless of what passed (even String.Empty). For this reason, itโs much faster to add a check and return 0 independently (just as if it were executing a loop).