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

VulpesPosted Nov 29, 2011, 3:53 PM
Sam HobbsPosted Nov 29, 2011, 3:25 PM
Sam HobbsPosted Nov 29, 2011, 2:59 PM
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.
Satyapriya NayakPosted Nov 29, 2011, 12:33 PM
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