What is the difference between int.Parse() and
Convert.toInt32().

Answer Posted / jyoti magdum

Both(Convert.ToInt32 and int.Parse) will return the same
result in
most of the cases.

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

If you print the result it will be same ie 32.

If suppose the string is the null (see the example below),
Convert.ToInt32 will throw ArgumentNullException error.

and the int.Parse will throw ArgumentNullException error.

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

Is This Answer Correct ?    2 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is double a decimal?

520


Can properties be private in c#?

483


Is string primitive?

499


What are the boolean data types in c#?

512


What is multithreading? What are the problems that comes with multithreading and how to manage them?

554






How does split work in c#?

490


What is difference between for and foreach loop in c#?

538


Why do we use public static void main in c#?

472


What is the purpose of a console table?

477


What is array and types of array in c#?

484


Is array immutable in c#?

486


What is the difference between malloc () and new?

496


Explain about CTS?

553


Is c# and .net same?

495


You have got 1 million parking slots. At a time a parking slot can be free or not. To get next slot easily which data structure to implement?

613