1

Int32.Parse(a)CType(a,int)和有什么区别 Convert.ToInt32(a)?我们什么时候可以使用它们?C# 中 CType 的等价物是什么?

4

1 回答 1

1

Int32.parse(字符串)

Int32.Parse (string s) 方法将数字的字符串表示形式转换为其等效的 32 位有符号整数。当 s 为空引用时,会抛出 ArgumentNullException。如果 s 不是整数值,则会抛出 FormatException。当 s 表示小于 MinValue 或大于 MaxValue 的数字时,会抛出 OverflowException。

Convert.ToInt32(字符串)

Convert.ToInt32(string s) 方法将指定的字符串表示形式转换为等效的 32 位有符号整数。这又调用了 Int32.Parse() 方法。当 s 为空引用时,它将返回 0 而不是抛出 ArgumentNullException。如果 s 不是整数值,则会抛出 FormatException。当 s 表示小于 MinValue 或大于 MaxValue 的数字时,会抛出 OverflowException。

于 2012-10-18T09:12:05.303 回答