Parse and Convert

  • Thread starter Thread starter alberto
  • Start date Start date
alberto said:
What's the difference between int.Parse(...) and Convert.ToInt32(...)?

int.Parse throws an exception if you pass it null. Convert.ToInt32
doesn't.

It's worth checking Google Groups before asking questions, by the way -
if you search for
difference Convert ToInt32 int Parse group:*.csharp
on groups.google.com, you get plenty of answers.
 
Pull out Reflector and you can see exactly what is going on.
Convert.ToInt32(string) actually directly calls int.Parse() after checking
for null.
 
Back
Top