Can String.Split() ever return null? (.net)

it cannot return, make sure your property is not empty

if (property != null)
{
    string[] splitData = sampleObject.property.Split(new char[] { ',' },
    StringSplitOptions.RemoveEmptyEntries);
}

No, it cannot return null. If you look at the source of it, it even guarantees it with code contracts:

public String[] Split(params char[] separator) {
    Contract.Ensures(Contract.Result<String[]>() != null);

All public overloads also make the same guarantee.


No, it doesn't return null. If the separator is not present, it returns the whole string

From MSDN

If this instance does not contain any of the strings in separator, the returned array consists of a single element that contains this instance. If the separator parameter is null or contains no characters, white-space characters are assumed to be the delimiters

Tags:

C#

.Net

String