Knowledge Check - Other Features
1. True/False. The
const keyword is equivalent to the
const is for compile-time constants.
readonly is a runtime constant. With
the compiler determines what value the constant has and substitutes that value anywhere the
code refers to it. It is slightly faster than
readonly, but is also much more limited.
2. What is the name of the class that lets you inspect (reflection) a type’s definition at runtime?
System.Type class is the primary origination point of reflection. Instances of
represent the metadata for a specific type available in the program.
3. What keyword allows you to jump to a named location elsewhere in the method?
goto. But don’t use it. Find a way to structure the code to avoid it, and use loops,
continues, and other similar features. You always end up regretting
4. What keyword will enable you to split a class’s definition into multiple parts?
partial keyword lets you split a type definition across multiple files (or even multiple slices
within a single file, though the first is more common).
5. Name two bit manipulation operators.
There are quite a few. The bitshift operators
<<, and the logical operators
6. True/False. An enumeration definition can contain a class definition.
False. While a class can contain other type definitions, including an enumeration or another class, enumerations cannot include additional type definitions.
7. True/False. A class definition can contain an enumeration definition.
True. Classes can contain other type definitions inside of them as members. This is typically done only when the nested type is very closely related to the containing type.
8. What preprocessor directives begin and end a section of
#if DEBUG starts a block that is only included when the
DEBUG symbol is defined, and
#endif will end it.
9. What keyword is involved when automatically cleaning up objects that implement
using keyword is reused for automatically cleaning up
IDisposable, as a part of
using directives at the top of the file).
10. True/False. You can create never-ending sequences with the
True. And this is one of the coolest features of
IEnumerables and the
yield keyword. You can produce
arbitrarily long sequences.