C#中double轉int時需要注意的地方


這是個很奇怪的問題  一個double的大於0的數字轉int后 竟然變成了負數

后來F12進入Int32里面看了發現 原來這個數字超過了Int32的最大值了
Int32的范圍:

        // 摘要:
        //     表示 System.Int32 的最大可能值。此字段為常數。
        public const int MaxValue = 2147483647;
        //
        // 摘要:
        //     表示 System.Int32 的最小可能值。此字段為常數。
        public const int MinValue = -2147483648;

Int16的范圍:

        // 摘要:
        //     表示 System.Int16 的最大可能值。此字段為常數。
        public const short MaxValue = 32767;
        //
        // 摘要:
        //     表示 System.Int16 的最小可能值。此字段為常數。
        public const short MinValue = -32768;

Int64的范圍:

 

        // 摘要:
        //     表示 Int64 的最大可能值。此字段為常數。
        public const long MaxValue = 9223372036854775807;
        //
        // 摘要:
        //     表示 Int64 的最小可能值。此字段為常數。
        public const long MinValue = -9223372036854775808;

 所以這里只能用Int64進行轉換了。。。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM