int i;

string s=null;

Console.WriteLine(Convert.ToInt32(s));   //值为0
Console.WriteLine(Int.TryParse(s,out i));   //值为true   i的值为0
Console.WriteLine(Int.Parse(s));   //抛出异常
注:object obj=123; int item=Convert.ToInt32(obj); 这样得到的item的值为null,而不会为123

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-02-27
  • 2022-12-23
  • 2022-03-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2021-08-08
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案