In C#, what is the best way to compare strings with null and "" return true

Viewed 9193

I have the following code (as i am trying to detect changes to a field)

 if (person.State != source.State)
 {
      //update my data . .
  }

the issue is I am having cases where person.State is NULL and source.State is "" and thus returning true.

If one is null and the other is an empty string, I want to treat them as equal and don't update my data. What is the cleanest way of doing that? Do i need to create my own Comparer object as this seems like a generic problem

10 Answers
Related