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




Answers were Sorted based on User's Feedback



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

Answer / joseph


I got this example through net..hope it helps you.
Both(Convert.ToInt32 and int.Parse) will return the same
result in
most of the cases. But null is handled differently.
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 ie 32.

If suppose the string is the null (see the example below),
Convert.ToInt32 will return zero.
but the int.Parse will throw ArgumentNullException error.

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

Is This Answer Correct ?    50 Yes 4 No

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

Answer / 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




More C Sharp Interview Questions

how can we pass parameters to a user control using delegates ?

1 Answers   IBM,


What are nullable types? Is Nullable<int> I and int ?i are same.

2 Answers   TCS,


6. If we assign a value in textbox on Page_UnLoad event, will it display?

2 Answers   Mphasis,


Why multiple Inheritence is not used in C#?

8 Answers   Symphony,


How to print labels in windows form in C# .net

5 Answers  






What is the difference between these statements obj=null and obj.dispose()

4 Answers   Fulcrum Logic,


Which layer executed first among these Application layer,Buisness layer or Data Base Layer?

2 Answers   L&T,


Can Any body send C Sharp latest interview questions to my mail id: alim.mtech@gmail.com.

1 Answers  


what is meant inheritance. can you exaplain what kind inhertance ussed in your project

1 Answers  


What?s an abstract class?

5 Answers  


i want the csharp questions&answeres

0 Answers   IBM, Siemens,


What?s class SortedList underneath?

1 Answers  






Categories