Possible Duplicate:
Why does “abcd”.StartsWith(“”) return true?
Something similar to this being true caught us out:
"FooBar".StartsWith(string.Empty)
Firstly I don't think it should be true but I am also not quite sure why it is true, looking at the "Reflector'ed" code:
public bool StartsWith(string value, bool ignoreCase, CultureInfo culture)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
if (this == value)
{
return true;
}
CultureInfo info = (culture == null) ? CultureInfo.CurrentCulture : culture;
return info.CompareInfo.IsPrefix(this, value, ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None);
}
ignoreCase is false and culture is null. So why does "this == value" evaluate to true?