<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Hopes

    Start Here..

     

    int int16 int32&&&&int.parse() convert.Int32()

    int
    -2,147,483,648 到 2,147,483,647
    int16
    -32768 到 32767
    int32
    -2,147,483,648 到 2,147,483,647

    int = int32

    在C#中:
    int <==> System.Int32
    short <==> System.Int16

    long <==> System.Int64


    intint.Parse()Convert.ToInt32()區(qū)別...

            直到自己親自測(cè)試了才對(duì)他們有所了解,以前就知道用最后面那個(gè),因?yàn)榕罗D(zhuǎn)化出錯(cuò),所以就用它比較安全。

    1.int (int)變量,C#默認(rèn)整型為int32(不支持bool轉(zhuǎn)化)

    2.int.Parse(string sParameter) 4個(gè)構(gòu)造函數(shù),參數(shù)類型只支持string類型;

    3.Convert.ToInt32()支持的類型是object

    事例:

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace IntegerSample
    {
        public class Program
        {
            private enum eNumber { Man = 1, Woman = 2 };

            private static char cNumber = 'e';
            private static byte btNumber = 12;
            private static long lNumber = 12345;
            private static double dNumber = 12.34d;
            private static decimal dlNumber = 4.5m;
            private static bool bNumber = true;

            private static string str = null;
            private static string str1 = "";
            private static string str2 = "123";
            private static string str3 = "Hello";

            public static void TransformByInt()
            {
                Console.WriteLine("{0} TransformByInt Into {1}", eNumber.Man, (int)eNumber.Man);
                Console.WriteLine("{0} TransformByInt Into {1}", cNumber, (int)cNumber);
                Console.WriteLine("{0} TransformByInt Into {1}", btNumber, (int)btNumber);
                Console.WriteLine("{0} TransformByInt Into {1}", lNumber, (int)lNumber);
                Console.WriteLine("{0} TransformByInt Into {1}", dNumber, (int)dNumber);
                Console.WriteLine("{0} TransformByInt Into {1}", dlNumber, (int)dlNumber);
                //Console.WriteLine("{0} TransformByInt Into {1}", bNumber, (int)bNumber);
                //Console.WriteLine("{0} TransformByInt Into {1}", str1, (int)str);
            }

            // Result: 1
            // Result
    101
            // Result: 12
            // Result: 12345
            // Result: 12
            // Result: 4
            //
    無(wú)法將類型“bool”轉(zhuǎn)換為“int”
            //
    編譯錯(cuò)誤,不能將string轉(zhuǎn)化為int

            public static void TransformByIntParse()
            {
                try
                {
                    Console.WriteLine("str {0}:", int.Parse(str));
                    Console.WriteLine("str1 {0}:", int.Parse(str1));
                    Console.WriteLine("str2 {0}:", int.Parse(str2));
                    Console.WriteLine("str3 {0}:", int.Parse(str3));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message.ToString());
                }
            }

            // 值不能為空。
            //
    輸入字符串的格式不正確。
            // Result: 123
            //
    輸入字符串的格式不正確。

            public static void TransformByConvert()
            {
                try
                {
                    Console.WriteLine("{0}", Convert.ToInt32(str));
                    Console.WriteLine("{0}", Convert.ToInt32(str1));
                    Console.WriteLine("{0}", Convert.ToInt32(str2));
                    Console.WriteLine("{0}", Convert.ToInt32(str3));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message.ToString());
                }
            }

            // Result: 0
            //
    輸入字符串的格式不正確。
            // Result: 123
            //
    輸入字符串的格式不正確。

            public static void Main(string[] args)
            {
                TransformByInt();
                TransformByIntParse();
                TransformByConvert();
            }
        }
    }

    ps
    C#不會(huì)對(duì)數(shù)據(jù)進(jìn)行四舍五入,只會(huì)截取。

    posted on 2012-10-24 20:31 ** 閱讀(317) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    統(tǒng)計(jì)

    公告

    你好!

    常用鏈接

    留言簿(2)

    隨筆檔案

    文章分類

    文章檔案

    新聞檔案

    相冊(cè)

    收藏夾

    C#學(xué)習(xí)

    友情鏈接

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲国产精品综合久久一线| 久久最新免费视频| 亚洲毛片在线免费观看| 亚洲精品无码午夜福利中文字幕 | 国产精品亚洲а∨无码播放不卡 | 免费精品视频在线| 四虎影视永久免费观看地址| 亚洲欧美在线x视频| 亚洲av无码天堂一区二区三区| 一级做a爰片久久毛片免费陪 | 亚洲高清免费在线观看| 亚洲码在线中文在线观看| 日本免费一区二区三区四区五六区| 亚洲人成电影福利在线播放| 1000部羞羞禁止免费观看视频| 亚洲精品在线免费观看视频| 免费观看黄网站在线播放| 亚洲精品无码av中文字幕| 免费一看一级毛片人| 在线免费视频你懂的| 亚洲国产精品婷婷久久| 在线观看无码AV网站永久免费| 亚洲第一成年免费网站| 国产成人亚洲精品影院| 91香焦国产线观看看免费| 亚洲色精品VR一区区三区| 免费人妻av无码专区| a级毛片免费在线观看| 亚洲欧洲日产专区| 永久免费bbbbbb视频| 久久久久久久久久久免费精品 | 国产亚洲精品无码拍拍拍色欲| 免费在线中文日本| 国产精品久久亚洲不卡动漫| 亚洲国产成人五月综合网 | 亚洲v高清理论电影| 日本精品人妻无码免费大全 | 99精品免费观看| 九九精品国产亚洲AV日韩| 国产亚洲A∨片在线观看| 可以免费看黄的网站|