1
I want to compare strings that come from two different sources. If they’re different, I’ll do something. Something like this:
if (foo != bar)
{
noop();
}
However, in my specific case, I am considering that an empty string and a null string are the same thing. In certain languages such as Javascript a code like this would be enough, but that’s not how it works in the world . NET...
string foo = null;
string bar = "";
foo == bar; // false;
I know I can solve my problem with some pre-conversion type:
foo = (foo != null ? foo : "");
bar = (bar != null ? bar : "");
But it bothers me, because it seems excessive. Is there any more minimalist way to make a comparison that considers null or empty as the same thing?
Good. This is close enough to what I want. I will create a method that does this check, and in case of false, compare the strings to each other.
– Oralista de Sistemas