The int version of the TryParse() methods converts string data to an int. The first argument is the string that you want to convert, and the second argument is an out parameter that receives the result if the conversion is successful, or 0 if it is not. The method returns a Boolean value that indicates whether the conversion was successful. Write this method using exception handling techniques to ensure that the method returns correctly whether or not the conversion is successful. Use the method Convert.ToInt32(inputString)to do the conversion.
What will be an ideal response?
The method should be similar to the following example:
public static bool TryParse(string inputString, out int number)
{
bool wasSuccessful = true;
try
{
number = Convert.ToInt32(inputString);
}
catch(FormatException e)
{
wasSuccessful = false;
number = 0;
}
return wasSuccessful;
}
Computer Science & Information Technology
You might also like to view...
The lower edge of the PC desktop screen displays a ________.
a. status bar b. menu bar c. command bar d. taskbar
Computer Science & Information Technology
A(n) ______ is software that enables users with an Internet connection to access and view webpages on a computer or mobile device.
Fill in the blank(s) with the appropriate word(s).
Computer Science & Information Technology