Search code examples
c#returndecompiling

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 >= 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


Solution

  • 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;
    }