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

What's the implicit name of the parameter that gets passed into the set method/property of a class?

802


What is string programming language?

637


What is the usage of transponders?

733


What method is used to sort the elements of the array in descending order?

754


What are object pooling and connection pooling and difference between them?

742


What is asp net c#?

698


What does mean c#?

721


Is c# good for web development?

750


Does c# support multilevel inheritance?

675


What are different types of classes in c#?

678


Why do we need interfaces in c#?

672


How do you declare a method in c#?

687


In which order the constructor is called for an inherited class?

737


Define thread?

781


What is alias in c#?

749