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 primitive types in c#?
Why do we still see so much non-oo code written in c# today?
What is the difference between a field and a property in c#?
What is a delegate? Explain.
What is the major difference between a custom control and user control?
What does the initial catalog parameter define in the connection string?
What is decimal in c#?
What is the full form of GAC? Explain its uses?
What is a class level variable in c#?
How to get the sum of last 3 items in a list using lambda expressions?
Explain the Usage of web.config
What is a sealed class?
What is callback function in c#?
Are c# generics the same as c++ templates?
How do you sort a list in c#?