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
What is difference between throw and throws in c#?
What is function c#?
Why do we use class in c#?
What is gui in c#?
Is type nullable c#?
Why can't we use a static class instead of singleton?
Explain the Different types of configuration files in .net?
What is entity framework in c#?
Which is executed if an exception has not occurred?
How many bytes is an int c#?
What are All kind of access specifiers for a class and for methods
What is the difference between static and private constructor in c#?
Why do we use classes?
Is int an object in c#?
Is dictionary a collection?