What is the difference between int.Parse() and
Convert.toInt32().
Answers were Sorted based on User's Feedback
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 |
Answer / 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 |
How can I get around scope problems in a try/catch?
How to raise an selection changed event associated with listbox in datagridview control with a sample example?Here the listbox is a child control associated with datagridview control.
How to generate strong name key file or which command is used to generated strong name key file?
What are custom exceptions in C#?
What is console write in c#?
Explain the constructor in c#.
what is meant inheritance. can you exaplain what kind inhertance ussed in your project
What is using directive in c#?
Is .net and c# the same?
Code to run exe like mspaint,autocad etc in asp.net.
What's the difference between a method and a procedure?
What are the ways to deploy an assembly?