Your teacher probably wants you to put it in there in case you go back and edit your code maybe?
Code: Select all
public bool IsNumeric(string s)
{
try
{
Double.Parse(s);
}
catch
{
return (false);
}
return (true);
}
First off this is a method which returns a
boolean value (true/false) and judging by the name
IsNumeric it tests a string if it is a number or not.
The method requires a string value which is labeled
s.
The
try catch allows you to try something without breaking your program. It will try whats in the block and catch an error which is in the
catch section and return false in this case.
Here you are trying to parse your string as a double. If you are successful, then you will return true, meaning that your string was a number.
If you aren't successful in parsing your string, then that means it wasn't a number and returns false.
So, that's what that method does.
But like
wearymemory said, you should ask your teacher about this stuff, but it's alright to come here and ask.
EDIT: I just noticed now that
wearymemory already gave an explanation lol... I didn't notice it at first, I thought you were just telling him not to ask here...