c. NumberStyles.Currency
d. All of the above.
What type does the “checked” block work for and what does it do?
Only for integer. It throws an exception when a narrowing conversion fails.
b. The source and destination types must be compatible.
What happens during a narrowing conversion that fails for floats? (Double to float)
The result float is set to infinity. Check for this with float.IsInfinity (static method)
c. Console.WriteLine(total.ToString
(“c”));
Are implicit conversions allowed for narrowing conversions?
No
c. String.Format(“{2}, {0}, {3}”,
“vidi”, “Venti”, “Veni”, “vici”)
If x were an Int32, what would you get by calling:BitConverter.GetBytes(x)
An array of bytes, 4 actually.
a. i = (int)l is a narrowing conversion.
How is a cast handled from float to int?
Truncate
d. TryParse
System.convert.toInt32 does what to a float-to-int conversion?
Rounds to nearest int.
c. Boxing
Once you cast a reference type to an ancestor class, can you use it again later as the original type?
Yes. It never really changes, it’s a reference (address) after all. You can simply “convert” it back, and no values are lost.
a. Person alice = new Employee();
Converting to an ancestor class is what kind of conversion? (Widening or narrowing?)
Widening. An explicit cast is required to go the other direction.
c. StopsWith
Will the following code throw?Person person = new Person();Employee employee = (Employee) person;
Yes, the underlying type is actually a Person not an employee.
d. Use the String class’s Space method passing it 10 as the number of spaces the string should contain.
The is operator will returns true for an object if…
The type being checked is in the class hierarchy of the type being tested.
a. checked
What will an as operator return if the types are incompatible.
A null object.
c. Check the result for the value Infinity or NegativeInfinity.