It should behave as documented:
If this instance does not contain any of the characters in separator
, the returned array consists of a single element that contains this instance.
An empty string clear does not contain any of the characters in separator
, hence an array is returned consisting of a single element referring to an empty string.
Of course, if you call Split
on a null reference, you'll get a NullReferenceException
. It's important to differentiate between a reference to an empty string and a null reference.
If you want the method to return an empty array, use StringSplitOptions.RemoveEmptyEntries
. If you want the result to be an error, you should check for this yourself and throw whatever exception you want.
It's important not to guess at behaviour when using an API though: if you're in any doubt at all, consult the documentation.