C# wpf 获取 数字 类型 所占字节数

        //获取数字类型所占字节
        public static int SizeBytesOfType(IConvertible number)
        {
            TypeCode typeCode = number.GetTypeCode();
            int bytesCount = 0;
            switch (typeCode)
            {
                case TypeCode.Boolean:
                    bytesCount = 1;
                    break;
                case TypeCode.Byte:
                    bytesCount = 1;
                    break;
                case TypeCode.Char:
                    bytesCount = 1;
                    break;
                case TypeCode.DBNull:
                    break;
                case TypeCode.DateTime:
                    break;
                case TypeCode.Decimal:
                    bytesCount = 12;
                    break;
                case TypeCode.Double:
                    bytesCount = 8;
                    break;
                case TypeCode.Empty:
                    break;
                case TypeCode.Int16:
                    bytesCount = 2;
                    break;
                case TypeCode.Int32:
                    bytesCount = 4;
                    break;
                case TypeCode.Int64:
                    bytesCount = 8;
                    break;
                case TypeCode.Object:
                    break;
                case TypeCode.SByte:
                    bytesCount = 1;
                    break;
                case TypeCode.Single:
                    bytesCount = 4;
                    break;
                case TypeCode.String:
                    break;
                case TypeCode.UInt16:
                    bytesCount = 2;
                    break;
                case TypeCode.UInt32:
                    bytesCount = 4;
                    break;
                case TypeCode.UInt64:
                    bytesCount = 8;
                    break;
                default:
                    break;
            }
            return bytesCount;
        }

 

转载于:https://www.cnblogs.com/changbiao/p/3464336.html

你可能感兴趣的:(C# wpf 获取 数字 类型 所占字节数)