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 the process of Serialization?

755


What you mean by delegate in c#?

678


Why c# is called c sharp?

658


What is inner class in c#?

720


What is property in c#?

704


Can mvc be used for desktop applications?

708


What is an int c#?

648


What do you mean by directing?

678


Write a syntax for writing a event delegate.

694


If a child class instance is created, which class constructor is called first - base class or child class?

712


What does dbml stand for?

741


Why do we need interfaces in c#?

664


What is c# in asp net?

670


What is the differences between datagrid, datalist and repeater in .net?

720


What is final keyword in c#?

703