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 a int in c#?
What is c# and why it is used for?
Can we override main method in c#?
You are designing a user control. You created new property called backgroundimage which is of type image. You wanted to disable storing this property in the user’s form. How to achieve this?
What does assert() do in c#?
If a child class instance is created, which class constructor is called first - base class or child class?
Can destructors have access modifiers?
Explain About multi level and multiple inheritance how to achieve in .net
What is the diff between System.String and System.Text.StringBuilder classes?
Describe the ways of cleaning up objects in c#.
What is a method c#?
Is c# scripting language?
What is the difference between array and arraylist in c#?
What is difference between value and reference types in C#.NET
List the 5 different access modifiers in c#?