Chapter 4 Flashcards
1
Q
To parse a string that might contain a currency value such as $1,234.56, you should pass the Parse or TryParse method which of the following values?
a. NumberStyles.AllowCurrencySymbol
b. NumberStyles.AllowThousands
c. NumberStyles.Currency
d. A combination of all NumberStyles values
A
C
2
Q
- Which of the following statements is true for widening conversions?
a. Any value in the source type can fit into the destination type.
b. The conversion will not result in loss of magnitude but may result is some loss of precision.
c. An explicit cast is optional.
d. All of the above.
A
D
3
Q
- Which of the following statements is true for narrowing conversions?
vThe conversion will not result in loss of magnitude but may result is some loss of precision.
b. The source and destination types must be compatible.
c. An explicit cast is optional.
d. A cast can convert a string into an int if the string holds numeric text.
A
B
4
Q
- Assuming total is a decimal variable holding the value 1234.56, which of the following statements displays total with the currency format $1,234.56?
a. Console.WriteLine(total.ToString());
b. Console.WriteLine(total.ToCurrency
String());
c. Console.WriteLine(total.ToString
(“c”));
d. Console.WriteLine(Format(“{0:C}”,
total);
A
C
5
Q
- Which of the following statements generates a string containing the text “Veni, vidi, vici”?
a. String.Format(“{0}, {1}, {2}”,
Veni, vidi, vici)
b. String.Format(“{1}, {2}, {3}”,
“Veni”, “vidi”, “vici”)
c. String.Format(“{2}, {0}, {3}”,
“vidi”, “Venti”, “Veni”, “vici”)
d. String.Format(“{Veni, vidi, vici}”)
A
- C
6
Q
- If i is an int and l is a long, which of the following statements is true?
a. i = (int)l is a narrowing conversion.
b. l = (long)i is a narrowing conversion.
c. l = (long)i could cause an integer overflow.
d. The correct way to copy i’s value into l is
l = long.Parse(i).
A
A
7
Q
- Which of the following methods is the best way to store an integer value typed by the user in a variable?
a. ToString
b. Convert
c. ParseInt
d. TryParse
A
D
8
Q
- The statement object obj = 72 is an example of which of the following?
a. Explicit conversion
b. Immutable conversion
c. Boxing
d. Unboxing
A
C
9
Q
- If Employee inherits from Person and Manager inherits from Employee, which of the following statements is valid?
a. Person alice = new Employee();
b. Employee bob = new Person();
c. Manager cindy = new Employee();
d. Manager dan = (Manager)
(new Employee());
A
A
10
Q
- Which of the following is not a String method?
a. IndexOf
b. StartsWith
c. StopsWith
d. Trim
A
C
11
Q
- Which of the following techniques does not create a String containing 10 spaces?
a. Set a String variable equal to a literal containing 10 spaces.
b. Use a String constructor passing it an array of 10 space characters.
c. Use a String constructor passing it the space character and 10 as the number of times it should be repeated.
d. Use the String class’s Space method passing it 10 as the number of spaces the string should contain.
A
D
12
Q
- Which of the following statements can you use to catch integer overflow and underflow errors?
a. checked
b. overflow
c. watch
d. try
A
A
13
Q
- Which of the following techniques should you use to watch for floating point operations that cause overflow or underflow?
a. Use a checked block.
b. Use a try-catch block.
c. Check the result for the value Infinity or NegativeInfinity.
d. Check the result for Error.
A
C
14
Q
. Which of the following are narrowing conversions?
a. Converting a byte to an integer
b. Converting a double to a float
c. Converting an integer to a long
d. Converting a float to a double
e. Converting an integer to a float
f. Converting a double to a long
g. Converting a decimal to an integer
h. Converting an integer to a decimal
A
- B, F, G
15
Q
- Which of the following are widening conversions?
a. Converting a byte to an integer
b. Converting a double to a float
c. Converting an integer to a long
d. Converting a float to a double
e. Converting an integer to a float
f. Converting a double to a long
g. Converting a decimal to an integer
h. Converting an integer to a decimal
A
- A, C, D, E, H