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




Answers were Sorted based on User's Feedback



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

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

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

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




More C Sharp Interview Questions

Why multiple Inheritence is not used in C#?

8 Answers   Symphony,


What is architecture of your poroject? how i c an say?

2 Answers   HCL, Phoenix Technologies, Eminosoft,


what are the best design patterns for C#.Net?

1 Answers  


what are delegates? How you used then in your project?

10 Answers   Kanbay, Hawk Eye, IndiaTimes,


How does a function pointer returns a function pointer?

3 Answers   Wipro,






What?s the difference between an interface and abstract class?

4 Answers  


What is the difference between array.find method and arraylist.find method?

1 Answers   Mphasis,


interface a { Method1() Method2() } class b: a { override Method1() override Method2() } what will happen & why?

5 Answers  


Using system; class main { public static void Main() { int a = 1; for (int i = 0; i < 10; i++) { int j = a * 5; Console.WriteLine(a + "*5=" + j); a++; } Console.ReadLine(); } }

1 Answers  


What is the Difference between value and reference type?

12 Answers   Wipro,


Explain constructor.

7 Answers   Wipro,


What is the use of giving more than one CATCH BLOCK in one TRY block? Directly we can give that catch(Exception e)?Why we go for arrayoutofbound Exception,divided by zero etc..? Explain

2 Answers  






Categories