Difference between Char.IsDigit() and Char.IsNumber() in C#

前端 未结 3 1219
情书的邮戳
情书的邮戳 2020-11-27 12:32

What\'s the difference between Char.IsDigit() and Char.IsNumber() in C#?

3条回答
  •  半阙折子戏
    2020-11-27 13:26

    I found the answer:

    Char.IsNumber() determines if a Char is of any numeric Unicode category. This contrasts with IsDigit, which determines if a Char is a radix-10 digit.

    Valid numbers are members of the following categories in UnicodeCategory:

    1. DecimalDigitNumber
      Decimal digit character, that is, a character in the range 0 through 9. Signified by the Unicode designation "Nd" (number, decimal digit). The value is 8.
    2. LetterNumber
      Number represented by a letter, instead of a decimal digit, for example, the Roman numeral for five, which is "V". The indicator is signified by the Unicode designation "Nl" (number, letter). The value is 9.
    3. OtherNumber
      Number that is neither a decimal digit nor a letter number, for example, the fraction ½. The indicator is signified by the Unicode designation "No" (number, other). The value is 10.

    Conclusion

    • Char.IsDigit:
      Valid digits are members of the DecimalDigitNumber category only.
    • Char.IsNumber:
      Valid numbers are members of the DecimalDigitNumber, LetterNumber, or OtherNumber category.

提交回复
热议问题