• Char.IsDigit与Char.IsNumber的区别


    需要判断Char是否为数字,查看了下MSDN,发现有三种方法:

    Char.IsDigit (aChar)              指示指定字符串中位于指定位置处的字符是否属于十进制数字类别

    Char.IsNumber(aChar)        指示指定字符串中位于指定位置的字符是否属于数字类别

    aChar>='0'&&aChar<='9'     判断aChar是否位于‘0’到‘9’之前  等同于第一种

    用.NET Reflector 查看其实现代码:

    public static bool IsNumber(char c)  
    1. {  
    2.     if (!IsLatin1(c))  
    3.     {  
    4.         return CheckNumber(CharUnicodeInfo.GetUnicodeCategory(c));  
    5.     }  
    6.     if (!IsAscii(c))  
    7.     {  
    8.         return CheckNumber(GetLatin1UnicodeCategory(c));  
    9.     }  
    10.     return ((c >= '0') && (c <= '9'));  
    11. }   
    public static bool IsDigit(char c)  
    1. {  
    2.     if (!IsLatin1(c))  
    3.     {  
    4.         return (CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.DecimalDigitNumber);  
    5.     }  
    6.     return ((c >= '0') && (c <= '9'));  
    7. }  

    Char.IsNumber 多了一步检查ASCII码。。。

  • 相关阅读:
    虚拟机添加新磁盘挂载,导致以前的文件丢失解决办法
    python实现tab键自动补全
    设计模式
    js 深浅拷贝 笔记总结
    js 闭包
    flex 布局
    vue2.0 之 生命周期
    移动端适配 rem
    vue 之 双向绑定原理
    vue2.0 之 过渡动画transtion
  • 原文地址:https://www.cnblogs.com/micro-chen/p/11557919.html
Copyright © 2020-2023  润新知