同桌上课用手指进去了好爽_欧美丰满熟妇xxⅹⅹ性大i_成人av天天日天天拍拍_猛男gay帅男gay男男同志_欧美va天堂在线观看_人妻无码av中文系列三里桃花_亚欧免费无码在线观看_久久久精品国产亚洲av水_日韩在线免费看污污污_2021无码专区人妻系列日韩

首頁 優(yōu)化推廣 c#中的int、int.parse、convert32之間的區(qū)別

c#中的int、int.parse、convert32之間的區(qū)別

來源: | 時(shí)間:2011/3/19 21:52:16 |

  直到自己親自測(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
        // 無法將類型“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));
  

服務(wù)熱線

153 8323 9821

功能和特性

價(jià)格和優(yōu)惠

網(wǎng)站和維護(hù)

推廣和優(yōu)化

微信服務(wù)號(hào)