Multi return statement STRANGE?
Today while playing with a De-compiler, i Decompiled the .NET C# Char Class and there is a strange case which i don't Understand
public static bool IsDigit(char c)
{
if (char.IsLatin1(c) || c开发者_StackOverflow社区 >= 48)
{
return c <= 57;
}
return false;
return CharUnicodeInfo.GetUnicodeCategory(c) == 8;//Is this Line Reachable if Yes How does it work !
}
i Used Telerik JustDecompile
Think your decompiler might be dodgy... With Reflector I get:
public static bool IsDigit(char c)
{
if (!IsLatin1(c))
{
return (CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber);
}
return ((c >= '0') && (c <= '9'));
}
And with ILSpy I get:
public static bool IsDigit(char c)
{
if (char.IsLatin1(c))
{
return c >= '0' && c <= '9';
}
return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber;
}
I assume that this is a bug in the decompiler you used.
In the .NET 4.0 framework, IL Spy shows the following code:
public static bool IsDigit(char c)
{
if (char.IsLatin1(c))
{
return c >= '0' && c <= '9';
}
return CharUnicodeInfo.GetUnicodeCategory(c)
== UnicodeCategory.DecimalDigitNumber;
}
It looks like the decompiler you used isn't very good at what it's doing.
Here's the output of dotPeek for that method:
public static bool IsDigit(char c)
{
if (!char.IsLatin1(c))
return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber;
if ((int) c >= 48)
return (int) c <= 57;
else
return false;
}
I think your decompiler lies.
dotPeek code:
public static bool IsDigit(char c)
{
if (char.IsLatin1(c))
{
if ((int) c >= 48)
return (int) c <= 57;
else
return false;
}
else
return CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber;
}
精彩评论