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 |
Which is the best way for keeping the data in XML or SQL server..and why?
is it possible to inherit a class but methods declared in the class should not be inheritable i possible how?
What is a Jagged Array in C#?
What is dll in c#?
Explain the difference between the debug class and trace class?
What is covariance and contravariance? Did Delegate and method overriding support these?
If you define a user defined data type by using the class keyword, is it a value type or reference type?
Do loops c#?
What are the properties of string?
What is a function c#?
i want display a given number into Rupees Format Like Given number is : 156735 my Expected output is 1,56,735. how to display?
How can we convert XML Data to DataBase Table in C#.Net?