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

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain namespaces in c#.

590


What is a static in c#?

494


What is the purpose of constructor in c#?

449


What are sessions in c#?

496


Can abstract class be sealed?

481






Why is dll used?

596


Explain the various types of classes used in c#?

503


What is instantiating a class in c#?

484


Define Abstract Class in C#

546


What is the difference between continue and break statement?

521


What is a class in unity?

484


How do you create dlls in .NET

576


Explain dataset.acceptchanges method in .net?

545


Why main is static in c#?

528


What are floating point numbers?

489