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 are collections in c#?

680


What Is A Multicast Delegate?

746


What is the use of tryparse in c#?

676


What is the difference between c and c sharp?

718


What is constructors, explain with syntax

723


What does .length do in c#?

724


Can you put two constructor with the same structure in a class?

701


How do you escape c#?

709


What do you know about device context?

718


You are designing a user control. You created new property called backgroundimage which is of type image. You wanted to disable storing this property in the user’s form. How to achieve this?

728


What are events in C#?

735


What is the namespace for the thread class?

719


Explain Direct CAST vs CType ?

752


how to Create a datagridview control with check box column with 8rows in it, the maximum number of check boxes checked should be 3, when user checks the 4th corresponding message should be displayed and check box should be checked. User can uncheck the checked boxes Note: read-only property should not be used

2597


What are the advantages of properties in c#?

734