Hi friends,
I want to know that, In which scenario, I should be using (int), Int32.Parse and Convert.ToInt32? are they same or not? I do notice in certain condition that i cannot cast directly using (int) and I have to use Convert.ToInt32.
I am not that sure why i do that. Further I just need some confirmations from you all.
Thank you.
Loading


Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 29, 2011, 7:33 AM EST
The Convert.ToInt32(String, IFormatProvider) underneath calls the Int32.Parse. So the only difference is that if a null string is passed to Convert it returns 0, whereas Int32.Parse throws an ArgumentNullException.
Refer
http://www.codeproject.com/KB/cs/AgileWare_Convert_Int32.aspx
Thanks
Sam HobbsRank #107 · 20.5K reputationPosted Nov 29, 2011, 9:59 AM EST
Usually it is better to use the Int32.TryParse Method, so that if the text is not a valid number your program will not crash.
Sam HobbsRank #107 · 20.5K reputationPosted Nov 29, 2011, 10:25 AM EST
VulpesRank #55 · 29.2K reputationPosted Nov 29, 2011, 10:53 AM EST