close

1.《 int.Parse() 》

ex: int.Parse 各式輸入值的狀況

------------------------------------------------------------------

int.Parse("20");   //20

int.Parse("1000000000000");   //OverflowException

int.Parse("a");   //FormatException

int.Parse(String.Empty);   //FormatException 

int.Parse(null);   //ArgumentNullException 

-------------------------------------------------------------------

2. 《Convert.ToInt32》

ex: Convert.ToInt32 各式輸入值的狀況

-------------------------------------------------------------------

Convert.ToInt32("20");   //True

Convert.ToInt32("1000000000000");   //OverflowException

Convert.ToInt32("a");   //FormatException

Convert.ToInt32(String.Empty);   //FormatException

Convert.ToInt32(null);   //0

---------------------------------------------------------------------------

3.《int.TryParse》各式輸入值的狀況

ex: int.TryParse 各式輸入值的狀況

---------------------------------------------------------------------------

int resultInt = 0;

int.TryParse("20"out resultInt);   //True

int.TryParse("1000000000000"out resultInt);   //False

int.TryParse("a"out resultInt);   //False

int.TryParse(String.Empty, out resultInt);   //False

int.TryParse(nullout resultInt);   //False

---------------------------------------------------------------------------

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 marcus0168 的頭像
    marcus0168

    Marcus

    marcus0168 發表在 痞客邦 留言(0) 人氣()