TryParse vs Convert

added by KodefuGuru
6/24/2010 9:00:15 AM


Since I’ve been coming out against out params, I sometimes get asked about the TryParse pattern. My typical response is that the most egregious offenses of out param usage occur when there is more than one, but even one should be avoided. However, I was recently presented with a more specific question: “lets say you had to pick up a query string param in WebForms/ASP.NET and make it an Int32... would use Convert or TryParse?” This is a very practical question, and given the choices it is interesting to examine for the best practice.