PrepAway - Latest Free Exam Questions & Answers

Which code segment should you add at line 19?

You are developing an application that includes the following 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?

PrepAway - Latest Free Exam Questions & Answers

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

Explanation:
B and C will throw exception when user enters non-integer value. D is exactly the opposite what we want to
achieve.
Int32.TryParse – Converts the string representation of a number to its 32-bit signed integer equivalent. A return
value indicates whether the conversion succeeded.http://msdn.microsoft.com/en-us/library/f02979c7.aspx


Leave a Reply