Data Types
Value Type
- Variable contains value directly
- Derived implicitly from the System.ValueType
- Cannot derive a new type from a value type.
example of value type - int, float, enum.
Builtin data types
apart from the above mentioned built in data types we need to discuss two special type of data types - Struct and Enum
Struct - A struct type is a value type that is typically used to encapsulate small groups of related variables
In the below example we are using a struct variable Book which has one decimal value price and two string variables title and author. Here we can see how to declare and use a struct variable.
Enum - The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list. In the below example we can see how to declare and use enum variables.
Reference Type
- Variables of reference types store references to their data
- Two variables can reference the same object; therefore, operations on one variable can affect the object referenced by the other variable
Dynamic Type
- The type is a static type, but an object of type dynamic bypasses static type checking
- At compile time, an element that is typed as dynamic is assumed to support any operation
Anonymous Type
- Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first
- The type name is generated by the compiler and is not available at the source code level
Comments
Post a Comment