Datatypes in C#

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.
          e.g. Every type inherits a ToString() method

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          float.
    - To create a double literal, just enter a decimal number. The compiler defaults to                     double literal when a decimal number is entered without a literal suffix.

    - To create a decimal literal, append the letter 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      decimal.

The CTS in .NET supports the follwoing five categories of types:

Comments