Difference between int.Parse(), Convert.ToInt32() and TryParse() in C#

Working on a Medullan project I saw int.Parse() being used interchangeably for
Convert.ToInt32() so I wondered what was the difference.

This link has the answer.

After writing this at 2am during a coding run, my CEO (who’s also a seasoned coder in his own right) recommended the TryParse() method for consideration. The TryParse() functionality has been extended to all common .NET data types as of ASP.NET 2.0, something that indicates it’s been performance tuned to be more extensible and perform better than similar existing functions.

So now I had a three way comparison, and not being one to reinvent the wheel and do load testing comparisons myself to figure which was most efficient, I ended up finding this article which showed why this is in fact, the new best practice for common data type conversions.

Leave a reply