Maderas
Maderas

Reputation: 241

C# Compare two strings with custom rules

Is there a way to use string.Equals or string.Compare in way that two nulls or two empty strings return false or a number other than 0 respectively?

Use Case:

string.Equals(null, null) = false;
string.Equals("", string.empty) = false;

string.Compare(null, null) != 0;
string.Compare("", string.empty) != 0;

Upvotes: 0

Views: 243

Answers (1)

Clive Ciappara
Clive Ciappara

Reputation: 558

You can try doing a not before like:

!string.Equals(null, null)

Upvotes: 1

Related Questions