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

Can I use ReaderWriterLock instead of Monitor.Enter/Exit for Threading?

520


Where is the main method in c#?

532


Is array thread safe c#?

482


What is the class in c#?

493


What is the system namespace?

478






What is Garbage Collection in .Net?

610


What are the types of comment in c# with examples?

483


What is difference between a function and a method?

499


Can I define a type that is an alias of another type (like typedef in c++)?

544


Why do we use inheritance in c#?

488


What is .net console?

535


Are cao stateful in nature?

476


Is typeof c#?

542


What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?

523


What does mean c#?

534