我在使用 Convert.Int32() 和 int32.Parse() 时有些困惑。
当我们使用 Convert.Int32() 或 int32.Parse()...
最佳答案
Convert.ToInt32() 将尝试将任何东西——无论是字符、 double 、对象,还是你有什么——转换成 Int32。 Int32.Parse() 仅适用于字符串。
编辑:为了回应 OP 的评论,我引用了 from this thread :
Basically the Convert class makes it easier to convert between all the base types.
The Convert.ToInt32(String, IFormatProvider) underneath calls the Int32.Parse. So the only difference is that if a null string is passed to Convert it returns 0, whereas Int32.Parse throws an ArgumentNullException.
It is really a matter of choice whichever you use.
关于.net - Convert.Int32() 和 Int32.Parse() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1500425/