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 is ioc containers c#?

636


What is use of FormBoarderStyle Propertie

679


Can you store different types in an array in c#?

671


What is difference between c sharp and c#?

637


Difference between call by value and call by reference in C#?

710






Which is better interface or abstract class in c#?

581


What is streamreader/streamwriter class?

675


Define satellite Assembly?

736


who is a protected class-level variable available to?

699


What is the use of static members with example using c#.net.

662


Explain About web methods and its various attributes

723


What is nullable types in c#?

657


What is a dimensional array?

610


Is c# slower than java?

641


What is delimiter in c#?

649