• [csharp] bool IsNumeric(Type type)


     1 /*
     2 "C:Program Files (x86)MSBuild14.0Bincsc.exe" /out:IsNumericType.exe IsNumericType.cs && start "IsNumericType.exe" IsNumericType.exe
     3 IsNumeric(System.Boolean) -> False
     4 IsNumeric(System.String) -> False
     5 IsNumeric(System.Char) -> False
     6 IsNumeric(System.Byte) -> True
     7 IsNumeric(System.Byte[]) -> False
     8 IsNumeric(System.DateTime) -> False
     9 IsNumeric(System.Int32) -> True
    10 IsNumeric(System.Single) -> True
    11 IsNumeric(System.Decimal) -> True
    12 IsNumeric(System.DayOfWeek) -> True
    13 IsNumeric(System.Guid) -> False
    14 IsNumeric(System.IntPtr) -> False
    15 IsNumeric(System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=ne
    16 utral, PublicKeyToken=b77a5c561934e089]]) -> False
    17 IsNumeric(System.Action) -> False
    18 Press any key to EXIT...
    19 */
    20 using System;
    21 using System.Reflection;
    22 
    23 static class Program {
    24     static bool IsNumeric(Type type) {
    25         switch (Type.GetTypeCode(type)) {
    26             case TypeCode.Byte:
    27             case TypeCode.SByte:
    28             case TypeCode.UInt16:
    29             case TypeCode.UInt32:
    30             case TypeCode.UInt64:
    31             case TypeCode.Int16:
    32             case TypeCode.Int32:
    33             case TypeCode.Int64:
    34             case TypeCode.Decimal:
    35             case TypeCode.Double:
    36             case TypeCode.Single:
    37                 return true;
    38             default:
    39                 return false;
    40         }
    41     }
    42 
    43     public static void Main() {
    44         Test(typeof(bool));
    45         Test(typeof(string));
    46         Test(typeof(char));
    47         Test(typeof(byte));
    48         Test(typeof(byte[]));
    49         Test(typeof(DateTime));
    50         Test(typeof(int));
    51         Test(typeof(float));
    52         Test(typeof(Decimal));
    53         Test(typeof(DayOfWeek));
    54         Test(typeof(Guid));
    55         Test(typeof(IntPtr));
    56         Test(typeof(int?));
    57         Test(typeof(Action));
    58         Console.Write("Press any key to EXIT...");
    59         Console.ReadKey(true);
    60     }
    61 
    62     static void Test(Type type) {
    63         Console.WriteLine("IsNumeric({0}) -> {1}", type.FullName, IsNumeric(type));
    64     }
    65 
    66 }
  • 相关阅读:
    平凡的世界
    MySql启动,提示:Plugin 'FEDERATED' is disabled....Cannot allocate memory for the buffer pool
    MySql开启慢查询报错:Could not open /var/log/slow_query.log for logging (error 13).
    ie浏览器,背景色兼容解决方法
    基于Bootstrap、Jquery的自适应导航栏
    chmod、chown、chgrp的意思
    Can't connect to MySQL server on localhost (0)
    mysql-bin引起mysql不能启动
    文件类型检测
    从数据库中查询规则
  • 原文地址:https://www.cnblogs.com/Bob-wei/p/7269874.html
Copyright © 2020-2023  润新知