Which code segment should you add at line 19?

You are developing an application that includes thefollowing code segment. (Line numbers are
included for reference only.)

You need to ensure that the application accepts only integer input and prompts the user each time
non-integer input is entered.
Which code segment should you add at line 19?

You are developing an application that includes thefollowing code segment. (Line numbers are
included for reference only.)

You need to ensure that the application accepts only integer input and prompts the user each time
non-integer input is entered.
Which code segment should you add at line 19?

A.
If (!int.TryParse{sLine, out number))

B.
If ((number = Int32.Parse(sLine)) = = Single.NaN)

C.
If ((number = int.Parse (sLine)) > Int32.MaxValue)

D.
If (Int32.TryParse(sLine, out number))



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Guilherme Morais

Guilherme Morais

Hi,
I found a type mismatch on letter A, can you please change the “{” for “(“.

Thanks in advance.

PS: I´m loving this tests, a Really BIG thanks

Herman McConnell

Herman McConnell

Right answer is D even if change { for ( in A. Cause we expect true statement from TryParse not false like in A ‘! int…’

Ashraf

Ashraf

In the first glance I chose D too, but the questions states that we need to prompt the user when the result is false, which makes A is the right answer due to (!), so in A it says if the tryparse result is false we will take action to notify the user and probably will return or set default value or re-ask for a new value, if not (If it’s a number), then number variable has the value and the code proceed.