The Type System Flashcards
Does every variable and constant have a type?
Yes.
Does every expression have a type?
Yes.
What information can be stored in a type?
Storage space, maximum and minimum, members, base type, interfaces it implements, and permitted operations
What does the compiler do with the type information when creating the executable?
It stores it as metadata that’s later used by the CLR to guarantee type safety.
What is the Common Type System (CTS)?
The fact that all types inherit from a common type, that for C# is System.Object.
What are value types?
Types derived from System.ValueType, these types directly contain their data.
Which are the value type categories?
structs and enums
Are value types sealed? What implies for a value type to be sealed?
Yes, it means that a type can’t derive from a value type.
What are reference types?
Types that hold references to an object stored in the heap, this reference might be null.
Which are the reference types?
Classes, interfaces, and delegates.
What are literal types?
Types that appear literally, like 5.
How can you alter the type of a numeric literal?
With suffixes, like f, that are used for floats, like 3.33f.
How can you get the type of a value?
With the GetType method.
How do you make the type implicit in a variable declaration?
With the var keyword, the type is set at compile-time based on the assignment.
How do you make value types nullable?
By appending a ? at the end of the type, like int?.