Multiple Return Operation STRANGE?

Today, playing with a De-compiler, I decompiled .NET C # Char Class, and there is a strange case that I do not 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 by Telerik JustDecompile

+5
source share
4 answers

Think your decompiler can 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;
}
+3
source

I assume this is an error in the decompiler used.

On the .NET 4.0 platform, 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;
}
+2
source

, , , , .

dotPeek :

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;
}
+1

, .

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;
    }
+1

All Articles