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
How will you allow a class to be inherited, but prevent the method from being over-ridden?
What is disconnected data architecture in c#?
Contrast between an interface and abstract class?
What is oledbconnection c#?
What is a view? What is the use of it?
Do loops in c#?
What is the default value of string in c#?
Explain the difference between Response.Write () and Response.Output.Write ().
What does do in c#?
What is Private Constructor? and it’s use? Can you create instance of a class which has Private Constructor?
List down the commonly used types of exceptions in .net
What do constructors do in c#?
What is inheritance in csharp?
Is c# easier than javascript?
What is dynamic dispatch?