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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you allow a class to be inherited, but prevent the method from being over-ridden?

509


What is disconnected data architecture in c#?

457


Contrast between an interface and abstract class?

520


What is oledbconnection c#?

478


What is a view? What is the use of it?

567






Do loops in c#?

481


What is the default value of string in c#?

532


Explain the difference between Response.Write () and Response.Output.Write ().

509


What does do in c#?

520


What is Private Constructor? and it’s use? Can you create instance of a class which has Private Constructor?

530


List down the commonly used types of exceptions in .net

476


What do constructors do in c#?

490


What is inheritance in csharp?

503


Is c# easier than javascript?

507


What is dynamic dispatch?

535