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...

If you want to only use cin and cout (but no other names) from the std namespace, you would

a. using std::cin; using std::cout; b. not be able to do it. c. cin and cout are not in the std namespace d. always have to say std::cin and std::cout e. Either A or D

Computer Science & Information Technology

Information stored on the Clipboard can include text, pictures, hyperlinks, and URLs

Indicate whether the statement is true or false

Computer Science & Information Technology

A _______ is a group of domains that share a contiguous namespace

a. Tree b. Branch c. Forest d. Organizational unit

Computer Science & Information Technology

Generalized audit software packages are used to assist the auditor in performing substantive tests.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology