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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. 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
  1. C
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Which of the following is not a String method?
    a. IndexOf
    b. StartsWith
    c. StopsWith
    d. Trim
A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
  1. B, F, G
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. 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
  1. A, C, D, E, H
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. If the Manager class inherits from the Employee class, and the Employee and Customer classes both inherit from the Person class, then which of the following are widening conversions?
    a. Converting a Person to a Manager
    b. Converting an Employee to a Manager
    c. Converting an Employee to a Person
    d. Converting a Manager to a Person
    e. Converting a Manager to an Employee
    f. Converting a Person to an Employee
    g. Converting a Customer to an Employee
    h. Converting an Employee to a Customer
A
  1. C, D, E
17
Q
  1. During which of the following conversions might there be a loss of precision?
    a. Converting an int to a float
    b. Converting a float to a long
    c. Converting a long to an int
    d. Converting an int to a long
    e. Converting a float to a decimal
    f. Converting a decimal to a float
A
  1. A, B, E, F
18
Q
  1. Suppose the Customer class inherits from the Person class, cust is a Customer variable that holds a reference to a Customer object, and person is a Person variable that holds a reference to a Person object. Then which of the following statements will fail at design time?
    a. cust = person;
    b. cust = person as Customer;
    c. cust = (Customer)person;
    d. person = cust;
    e. person = cust as Person;
    f. person = (Person)cust;
A

A

19
Q
  1. Suppose the Customer class inherits from the Person class, cust is a Customer variable that holds a reference to a Customer object, and person is a Person variable that holds a reference to a Person object. Then which of the following statements will fail at run time?
    a. cust = person;
    b. cust = person as Customer;
    c. cust = (Customer)person;
    d. person = cust;
    e. person = cust as Person;
    f. person = (Person)cust;
A
  1. C
20
Q
  1. Which of the following methods enables a program to parse an integer entered in a TextBox by the user?
    a. int.Parse
    b. int.TryParse
    c. string.Parse
    d. string.ParseInt
    e. System.Convert.ToInt32
A
  1. A, B, E
21
Q
  1. Which of the following string methods breaks a delimited string into pieces?
    a. ToArray
    b. Split
    c. Fields
    d. Join
A
  1. B
22
Q
  1. Which of the following string methods combines an array of values into a single delimited string?
    a. FromArray
    b. Fields
    c. Join
    d. Merge
A
  1. C
23
Q
  1. Which of the following statements correctly casts a float into an int?
    a. int value = (float)fvalue
    b. int value = (int)fvalue
    c. int value = ToInt(fvalue)
    d. float value = (int)fvalue
A
  1. B
24
Q
  1. Which of the following methods does not convert a floating point value into an integer type value?
    a. Convert.ChangeType
    b. Convert.ToInt16
    c. Convert.ToInt32
    d. Type.ToInt32
A

D

25
Q
  1. Which of the following methods lets you retrieve four 16-bit values that are packed into a 64-byte value returned by an API function?
    a. BitConverter.ToInt
    b. BitConverter.FromInt64
    c. (int)
    d. BitConverter.ToInt16
A
  1. D
26
Q
  1. Which of the following methods converts a 32-bit integer value into an array of bytes?
    a. BitConverter.ToBytes
    b. BitConverter.GetBytes
    c. BitConverter.ToArray
    d. ToArray
A

B

27
Q
  1. In the following two statements, where does boxing occur?
    int i = 1337;
    Console.WriteLine(string.Format(“i is: {0}”, i));
    a. Storing 1337 in an int requires that 1337 be boxed.
    b. The string.Format method must box its first parameter.
    c. The string.Format method must box its second parameter.
    d. The Console.WriteLine method must box the result of the string.Format method.
A
  1. C
28
Q
  1. After executing the following two C# statements, which of the following is true?
    int i = 10;
    object iObject = i;
    a. Variable i holds the value 10.
    b. Variable iObject holds the value 10.
    c. If you later change the value of iObject, the value of i remains unchanged.
    d. All the above.
A
  1. D
29
Q
  1. When working with API functions, a variable with a name that begins with lpsz has what data type?
    a. String
    b. 32-bit integer
    c. Character array
    d. Boolean
A
  1. A
30
Q
  1. What purpose does a dynamic data type serve?
    a. It enables the program to store more than one kind of data in a variable.
    b. It enables the program to convert a value from one type to another automatically without casting.
    c. It enables Visual Studio to defer type checking until run time.
    d. It prevents type checking.
A
  1. C
31
Q
  1. Which of the following methods formats the variable amount as currency?
    a. value.ToString(“C”)
    b. value.ToString(“$”)
    c. value.ToString(“$#,###.00”)
    d. value.ToCurrency()
A

A

32
Q
  1. Which of the following methods converts the current date into a string that is appropriate for the user’s locale?
    a. DateTime.Now.ToString(“mm/dd/yy”)
    b. DateTime.Now.ToString(“D”)
    c. DateTime.Now.ToString(“d”)
    d. DateTime.Now.ToShortDateString()
A

B, C, and D

33
Q
  1. If the Manager class inherits from the Employee class, and the Employee and Customer classes both inherit from the Person class, then which of the following are narrowing conversions?
    a. Converting a Person to a Manager
    b. Converting an Employee to a Manager
    c. Converting an Employee to a Person
    d. Converting a Manager to a Person
    e. Converting a Manager to an Employee
    f. Converting a Person to an Employee
    g. Converting a Customer to an Employee
    h. Converting an Employee to a Customer
A
  1. A, B, F . (In a sense you could technically consider g and h to be considered narrowing conversions, but actually they are just invalid conversions.)