int numVal = Convert.ToInt32("29");
numVal++;

Console.WriteLine(numVal);
// Output: 30

================================================= 

 

int numVal = Int32.Parse("-105");
Console.WriteLine(numVal);
// Output: -105

================================================== 

int j;
Int32.TryParse("-105"out j);
Console.WriteLine(j);
// Output: -105

================================================== 

 

try
{
    int m = Int32.Parse("abc");
}
catch (FormatException e)
{
    Console.WriteLine(e.Message);
}
// Output: Input string was not in a correct format.

=================================================== 

 

string inputString = "abc";
int numValue;
bool parsed = Int32.TryParse(inputString, out numValue);

if (!parsed)
    Console.WriteLine("Int32.TryParse could not parse '{0}' to an int.\n", inputString);

// Output: Int32.TryParse could not parse 'abc' to an int.

相关文章:

  • 2021-12-31
  • 2022-02-25
  • 2021-10-07
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2021-08-30
  • 2021-05-20
  • 2021-06-28
相关资源
相似解决方案