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?
The original code (from the reference source) is
public static 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;
}
You're seeing the output of a poor decompiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With