Saturday, January 29, 2011

Difference between int.parse and Convert.ToInt32

Consider the following example…

string strCount="32";
int count1 = Convert.ToInt32(strCount);
int count2 = int.Parse(strCount);

If you print the result it will be same i.e. 32

If suppose the string is the null,
Convert.ToInt32 will return zero.
but the int.Parse will throw ArgumentNullException error.

string strCount=null;
int count1 = Convert.ToInt32(strCount); // Returns 0
int count2 = int.Parse(strCount); // Error

1 comment:

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...