zoukankan      html  css  js  c++  java
  • 取得一个对象的具体类型

     public static string GetType(object source)
     {
        if (source == null)   

           {
                    return "null";
            }

                var type = source.GetType();
                switch (Type.GetTypeCode(type))
                {
                    //数值型
                    case TypeCode.Byte:
                    case TypeCode.Decimal:
                    case TypeCode.Double:
                    case TypeCode.Int16:
                    case TypeCode.Int32:
                    case TypeCode.Int64:
                    case TypeCode.SByte:
                    case TypeCode.Single:
                    case TypeCode.UInt16:
                    case TypeCode.UInt32:
                    case TypeCode.UInt64:
                        return source.ToString();
                    case TypeCode.Object:
                        break;
                    case TypeCode.Boolean:
                        return (bool)source ? "true" : "false";
                    case TypeCode.DBNull:
                        return "null";
                    default:
                        return "\"" + source + "\"";
                }

    }

  • 相关阅读:
    javaweb(五)——Servlet开发(一)
    JDK1.8改为JDK1.7过程
    javaweb(四)——Http协议(请求头,响应头详解)
    JavaWeb(三)——Tomcat服务器(二)
    JavaWeb(二)——Tomcat服务器(一)
    JavaWeb——JavaWeb开发入门
    java学习之异常总结
    java学习之异常之覆盖
    java学习之异常之格式
    java学习之异常之finally
  • 原文地址:https://www.cnblogs.com/wangsx/p/2205694.html
Copyright © 2011-2022 走看看