Rosmarine Popcorn
Rosmarine Popcorn

Reputation: 10965

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

Upvotes: 5

Views: 188

Answers (4)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

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

Upvotes: 2

MrKWatkins
MrKWatkins

Reputation: 2668

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

Upvotes: 3

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56222

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

Upvotes: 1

dtb
dtb

Reputation: 217401

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

Upvotes: 1

Related Questions