Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2084

Difference between Parsing, Converting and CType()

What's the difference between Int32.Parse(a), CType(a,int) and Convert.ToInt32(a)? And when we can use them? What is the equivalent for CType in C# ?

Upvotes: 2

Views: 1711

Answers (1)

John Woo
John Woo

Reputation: 263723

Int32.parse(string)

Int32.Parse (string s) method converts the string representation of a number to its 32-bit signed integer equivalent. When s is a null reference, it will throw ArgumentNullException. If s is other than integer value, it will throw FormatException. When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException.

Convert.ToInt32(string)

Convert.ToInt32(string s) method converts the specified string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method. When s is a null reference, it will return 0 rather than throw ArgumentNullException. If s is other than integer value, it will throw FormatException. When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException.

Upvotes: 2

Related Questions