I usually do this:
void Incoming(String str)
{
if (str == "")
{
}
}
But I've seen others' code do this:
void Incoming(String str)
{
if (str == String.Empty)
{
}
}
In my case I know str shouldn't be null. So would the following be a good idea instead, given it will cause an exception if the string is null rather than hiding the problem:
void Incoming(String str)
{
if (str.Length == 0)
{
}
}
And I've noticed this being used too, but this seems to accept the string might be null, rather than going and fixing the reason it is null. Is it a good idea to silently handle strings being null?
void Incoming(String str)
{
if (String.IsNullOrEmpty(str))
{
}
}