Folks, I was looking at the implementation of string.IsNullOrWhiteSpace in:
http://typedescriptor.net/browse/types/9331-System.String
Here is the implementation:
public static bool IsNullOrWhiteSpace(string value)
{
if (value == null)
{
return true;
}
for (int i = 0; i < value.Length; i++)
{
if (char.IsWhiteSpace(value[i]))
{
}
else
{
goto Block_2;
}
}
goto Block_3;
Block_2:
return false;
Block_3:
return true;
}
Question: Isn't this over complicated? Can't the following implementation do the same job and be easier on the eye:
bool IsNullOrWhiteSpace(string value)
{
if(value == null)
{
return true;
}
for(int i = 0; i < value.Length;i++)
{
if(!char.IsWhiteSpace(value[i]))
{
return false;
}
}
return true;
}
Is this implementation incorrect? Does it have a performance penalty?