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# ?

- 1,684
- 34
- 105
- 191
-
Be aware that [reposting a closed question](http://stackoverflow.com/questions/12945211/difference-among-directcast-trycast-ctype-convertto-and-parsing) may annoy some people. I suppose you are trying to find out about `ConvertTo` and `Int32.Parse`? – MarkJ Oct 18 '12 at 10:37
-
There is no exact equivalent of `CType` in C#. Have you seen http://stackoverflow.com/a/748785/15639 ? – MarkJ Oct 18 '12 at 14:04
-
That part of your question not answered by John Woo is a duplicate of http://stackoverflow.com/q/423820/256431 – Mark Hurd Oct 19 '12 at 05:15
1 Answers
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.

- 258,903
- 69
- 498
- 492