// 字符串轉換成整數
int numVal = Convert.ToInt32("26");
numVal++;
Console.WriteLine( numVal );
int numVal = Int32.Parse("-105");
Console.WriteLine( numVal );
int j ;
Int32.TryParse("-109",out j);
Console.WriteLine("j 的數值是:"+j );
try
{
int m = Int32.Parse("abc"); // 直接使用它轉換會報錯。 要加上報錯裝置
}catch (FormatException e)
{
Console.WriteLine(e.Message);
}
//這樣的方式 如果有錯就是返回0
int p ;
Int32.TryParse("abc",out p);
Console.WriteLine( "p 的數值是:"+ p );
string inputString = "abc";
int numValue ;
bool pared = Int32.TryParse(inputString ,out numValue);
// 接受的數值是0 但是返回的類型是 bool
Console.WriteLine( "numValue 的數值是:"+ numValue );
Console.WriteLine( "返回的bool:"+ pared );
