What is the difference between int.Parse() and
Convert.toInt32().
Answer Posted / 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 View All Answers
What is lazy t?
Is c# easier than c++?
What is the difference between method parameters and method arguments. Give an example?
What is c# best for?
What you mean by delegate in c#?
What is difference between virtual and override in c#?
What are the extension methods in c#?
Explain About Assembly in .NET, types of assemblies, their difference, How to register into GAC. How to generate the strong names & its use.
What is delegates in c# and uses of delegates?
What is a delegate? Explain.
Does c# support multiple inheritance (mi)?
How do we achieve encapsulation in c#?
What is the purpose of a namespace?
How many types of inheritance are there in c#?
In the page load event I assigned dropdownlist’s datasource property to a valid list. On the submit button click.. The same datasource property is coming as null. Why?