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 are extender provider components?
What are the new features in c# 2.0?
Explain About remoting and web services. Difference between them
Which config file has all the supported channels/protocol?
Write a console application and implement the ternary operator to decide whether the age a user entered after being prompted is allowed to vote or not(given that only citizens between 18 and 120 years only inclusive can vote). Use exception handling for non-numerical input.
What are All kind of access specifiers for a class and for methods
Is stringbuilder thread safe c#?
What is generic delegates in c#?
Can an exception be thrown from a catch block?
Explain the difference between directcast and ctype.
Why do we need a singleton class?
What is toint32 c#?
Is a dll an assembly?
What is managed code?
What is static classes?