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 type keyword in c#?
How do I count the length of a string in c#?
How can I use .NET components from COM programs?
What is cookies in c# asp net?
How does bitwise work?
Why reflection is used in c#?
What does exclamation mark mean c#?
What is data reader in c#?
What is xpath in c#?
What is out in c#?
What is difference between private and static constructor?
Are enums static c#?
What is the use of base keyword? Tell me a practical example for base keyword’s usage?
Why is aws serverless?
What is difference between tostring() vs convert.tostring() vs (string) cast