/// <summary>
        /// MS
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static int ToIn32(object o)
        {
            if (o != null)
            {
                return ((IConvertible)o).ToInt32(null);
            }
            return 0;
        }

        /// <summary>
        /// CSDN
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        static int ToInt(object o)
        {
            if (o is int)
                return (int)o;
            else if (o is short)
                return (int)(short)o;
            else if (o is byte)
                return (int)(byte)o;
            else if (o is long)
                return (int)(long)o;
            else if (o is double)
                return (int)(double)o;
            else if (o is float)
                return (int)(float)o;
            else if (o is decimal)
                return (int)(decimal)o;
            else if (o is uint)
                return (int)(uint)o;
            else if (o is ushort)
                return (int)(ushort)o;
            else if (o is ulong)
                return (int)(ulong)o;
            else if (o is sbyte)
                return (int)(sbyte)o;
            else
                return (int)double.Parse(o.ToString());
        }

http://msdn.microsoft.com/zh-cn/library/system.iconvertible.aspx

相关文章:

  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-10
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-08-19
相关资源
相似解决方案