I am curious to know what the difference is between a cast to say an int
compared to using Convert.ToInt32()
. Is there some sort of performance gai
See Diff Between Cast and Convert on another forum
The Convert.ToInt32(String, IFormatProvider) underneath calls the Int32.Parse (read remarks).
So the only difference is that if a null string is passed it returns0
, whereasInt32.Parse
throws anArgumentNullException
.
It is really a matter of choice whichever you use.
Personally, I use neither, and tend to use the TryParse
functions (e.g. System.Int32.TryParse()).
Link on top is broken, see this answer on StackOverflow.