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 xor operation?

689


What is Event - Delegate?

760


how to compare numbers and dispaly the largest ? *first thing I wanted to do is to input how many numbers to be compared *and then analyzed the largest then display it.

1457


Is int a class in c#?

706


Explain About multi level and multiple inheritance how to achieve in .net

754






Define Abstract Class in C#

716


What will a loop recorder show?

717


Expalin the way you implement inheritance by using VB.NET/C#?

704


There were a lot of questions asked, so I will list the topic (and add a what is "topic" and know pros/cons). Extreme programming, what is a transaction, various SDLC design approaches, what is a namespace, define a good test case, what is a stored proc, webservice? design patterns? linker? compiler? access modifiers? stack vs. queue? arrays vs. linked lists? sorting algorithms? recursion? OOP principles?

1761


What do u mean by thread safe?

669


What is a dimensional array?

610


Is c# code is managed or unmanaged code?

646


Does c# support c type macros?

698


What is the use of delegate?

704


Why is xml called extensible?

640