C# has a unified type system aka Common type system (CTS)
- A unified type system implies that all the types, including premitives such as integers are subclasses of the System.Object class
- Object class is the ultimate base class of all .NET classes; it is the root of the type hierarchy.
CTS separates data types into two categories
- Reference types : Data types whose objects are represented by a reference (similar to a pointer) to the object's actual value. If a reference type is assigned to a variable, that variable references (points to) the original value. No copy is made.
- Value types : Data types whose objects are represented by the object's actual value. If an instance of a value type is assigned to a variable, that variable is given a fresh copy of the value.
float ~6-9 digits
double ~15-17 digits
decimal 28-29 digits
Here, precision reflects the number of digits past the decimal that are accurate.
- To create a float
literal, append the letter F
after the number. In this context, the F
is called a literal suffix. The literal suffix tells the compiler you wish to work with a value of float
type. You can use either a lower-case f
or upper-case F
as the literal suffix for a float
.
- To create a double
literal, just enter a decimal number. The compiler defaults to a double
literal when a decimal number is entered without a literal suffix.
m
after the number. In this context, the m
is called a literal suffix. The literal suffix tells the compiler you wish to work with a value of decimal
type. You can use either a lower-case m
or upper-case M
as the literal suffix for a decimal
.The CTS in .NET supports the follwoing five categories of types:
- Classes
- Reference type that can be derived directly from another class and that is derived implicitly from System.Object.
- Structures
- Value type, derived from System.Object, In .NET, all primitive data types (Boolean, Byte, Char, DateTime, Decimal, Double, Int16, Int32, Int64, SByte, Single, UInt16, UInt32, and UInt64) are defined as structures.
- Enum : Value types
- Interfaces : Reference types
- Delegates : Reference types
Comments
Post a Comment