If the string is not in a valid format, Parse throws an exception.
int m = Int32.Parse(“abc”);
Because, here “abc” is not convertible into int.
So, Will u use Try Catch ???
In C#, we hv TryParse method that does not throw an exception but returns false.
Program:
string s = “abc”;
int k;
bool parsed = Int32.TryParse(s, out k);
if (!parsed)
Console.WriteLine(“Int32.TryParse could not parse ‘{0}’ to an int.\n”, s);
Output:
Int32.TryParse could not parse ‘abc’ to an int.
Advertisements