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

What is unsigned int?

518


What is dependency injection in simple words?

496


Why do we need oops in c#?

466


What is the difference between constants and read-only?

463


Distinguish between a class and struct?

495






Is struct object oriented?

470


What is the example of predicate?

494


What are floating point numbers?

481


What is difference between for and foreach in c#?

460


What is object array in c#?

495


What is data dictionary in c#?

480


What is the benefit of interface in c#?

469


Why do we use dataset in c#?

475


Explain Direct CAST vs CType ?

546


What is the use of flag in c#?

479