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
Can firstordefault return null?
Can abstract class be sealed in c#?
Explain the use of SN.exe
How does inheritance work in c#?
What is the default boolean value in c#?
Can you have more than one namespace in c#?
Is constructor a static method?
Is c# a strongly-typed language?
What is callback function in c#?
What method is used to sort the elements of the array in descending order?
In .Net, what is an assembly? Also explain the type of assembly.
Why do we use yield in c#?
What is the object class in c#?
How to declares a two-dimensional array in C#?
What is yield keyword?