Type System Flashcards
What is a type?
Type defines a blueprint for a value.
What is a predefined type?
What are some predefined types?
Predefined is a type that is specially supported by the compiler. In C#, predefined types are recognized with a C# keyword.
Examples of predefined types are: int, string, bool
https://stackoverflow.com/questions/13464641/c-sharp-predefined-types-vs-primitive-types/46866599#46866599
How is data created?
Data is created by instantiating a type.
How is a predefined type instantiated?
Simply by using a literal, such as 12 or “Hello, world”
How is a custom type instantiated?
Using “new” operator.
MyType instanceOfType = new MyType();
What comprises value types?
Most built-in types (all numeric types, char and bool types) as well as custom struct and enum types.
What comprises the reference types?
Class, array, delegate and interface types. String type is a reference type as well.
What does a reference-type variable contain?
A reference-type variable contains a reference to an object that contains the value.
What is the difference between reference and value types in regards to them containing null value?
Reference types can be assigned null value which means that they point to no object. Value types cannot ordinarily have a null value. (Exception: nullable value types)
Are all types from System namespace predefined in C#?
No. System namespace contains many types that are not predefined by C#. For example DateTime.
Is System.DateTime type predefined in C#?
No.
List 4 type categories in C#.
- Value types.
- Reference types.
- Generic type parameters.
- Pointer types.
How is anonymous type created?
To create an anonymous type use “new” operator with the object initializer.
var v = new { Amount = 108, Message = “Hello” };
In this case “Amount” and “Message” are user defined object properties and their type will be derived by the compiler.
Are methods and events allowed in anonymous types?
No. Only properties are allowed to be defined in the anonymous type.
What is accessibility level of properties in an anonymous type?
Properties of an anonymous type are read-only.