[csharp] bool IsNumeric(Type type)
2024-09-04 12:27:16
/*
"C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe" /out:IsNumericType.exe IsNumericType.cs && start "IsNumericType.exe" IsNumericType.exe
IsNumeric(System.Boolean) -> False
IsNumeric(System.String) -> False
IsNumeric(System.Char) -> False
IsNumeric(System.Byte) -> True
IsNumeric(System.Byte[]) -> False
IsNumeric(System.DateTime) -> False
IsNumeric(System.Int32) -> True
IsNumeric(System.Single) -> True
IsNumeric(System.Decimal) -> True
IsNumeric(System.DayOfWeek) -> True
IsNumeric(System.Guid) -> False
IsNumeric(System.IntPtr) -> False
IsNumeric(System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=ne
utral, PublicKeyToken=b77a5c561934e089]]) -> False
IsNumeric(System.Action) -> False
Press any key to EXIT...
*/
using System;
using System.Reflection; static class Program {
static bool IsNumeric(Type type) {
switch (Type.GetTypeCode(type)) {
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
case TypeCode.Decimal:
case TypeCode.Double:
case TypeCode.Single:
return true;
default:
return false;
}
} public static void Main() {
Test(typeof(bool));
Test(typeof(string));
Test(typeof(char));
Test(typeof(byte));
Test(typeof(byte[]));
Test(typeof(DateTime));
Test(typeof(int));
Test(typeof(float));
Test(typeof(Decimal));
Test(typeof(DayOfWeek));
Test(typeof(Guid));
Test(typeof(IntPtr));
Test(typeof(int?));
Test(typeof(Action));
Console.Write("Press any key to EXIT...");
Console.ReadKey(true);
} static void Test(Type type) {
Console.WriteLine("IsNumeric({0}) -> {1}", type.FullName, IsNumeric(type));
} }
最新文章
- 【原】IOS合并lib(.a)库的终极可用方法(可用于解决duplicate symbol静态库冲突)
- mysql count(*)和count(列)速率
- U-boot的环境变量值得注意的有两个: bootcmd 和bootargs
- Matlab 的reshape函数(转)
- PERCENT_RANK
- 【转】Dubbo是Alibaba开源的分布式服务框架
- Android 向系统添加一个联系人信息contact
- 简单的SqlHelper
- 获取ini文件所有的Sections和Keys
- Leetcode:minimum_depth_of_binary_tree解决问题的方法
- struts2 action 页面与action参数的传递的三种方式
- UVAlive-2554 Snakes &; Ladders---BFS状态的存储
- C++:如何删除string对象的末尾非数字字符
- .net core 在网络高并发下提高JSON的处理效率
- 2019-01-28 [日常]Beyond的歌里最多是";唏嘘";吗? - Python分词+词频
- 基于MVC 的Quartz.Net组件实现的定时执行任务调度
- python基础一 ------如何获取多个字典相同的键
- Luogu4717 【模板】快速沃尔什变换(FWT)
- js字符串和数组
- Atom Editor 插件 atom-less 的使用方法
热门文章
- pip安装lxml报错 Fatal error in launcher: Unable to create process using '";c:\users\administrator\appdata\local\programs\python\python36\python.exe"; ";C:\Users\Administrator\AppData\L
- Django的模型层(1)- 单表操作(下)
- 008-shiro与spring web项目整合【二】认证、授权、session管理
- 收藏一些好用的c语言数据结构
- WebService SOAP WSDL UDDI 使用php的curl、PHP5的SoapClient实现同步
- vue组件的is特性
- 07 Spring框架 依赖注入(四)基于注解的依赖注入
- POJ 1659 Frogs' Neighborhood (Havel定理构造图)
- SSO 单点登录的实现原理
- case的嵌套使用