Sunday 17 February 2013

Data type in C#.net

  • Data type in C#

    There are two types of data type in C#:
    1.A built-in data type
    2.A user-defined data type

    built-in data type are further divided as:
    byte
    short
    int
    float
    double
    long
    char
    bool
    datetime
    string
    object
    etc

    A user-defined data type are further divided as:
    class
    struct
    enum
    interface
    delegate
    array

    Encoding Scheme  To represent coding scheme.
    ASCII                8 bits                         28     =      256
    ANSI                 7 bits                         78     =      128
    Unicode character sets  16 bits           216    =         65000
    UTF (Unicode text file) can be:
    UTF  7
    UTF  8
    UTF  16
    UTF  32

    Integer Type


    C# supports eight predefined integer types:
    Name
    CTS Type
    Description
    Range
    sbyte
    System.SByte
    8-bit signed integer
    -128 to 127 (-27 to 27-1)
    short
    System.Int16
    16-bit signed integer
    -32768 to 32767 (-215 to 215-1)
    int
    System.Int32
    32-bit signed integer
    -2147483648 to
    2147483647 (-231 to 231-1)
    long
    System.Int64
    64-bit signed integer
    -9223372036854775808 to
    9223372036854775807 (-263 to 263-1)
    byte
    System.Byte
    8-bit unsigned integer
    0 to 255 (0 to 28-1)
    ushort
    System.UInt16
    16-bit unsigned integer
    0 to 65535 (0 to 216-1)
    uint
    System. UInt32
    32-bit unsigned integer
    0 to 4294967295 (0 to 232-1)
    ulong
    System. UInt64
    64-bit unsigned integer
    0 to 18446744073709551615 (0 to 264-1)


    Floating Point Type

    Name
    CTS Type
    Description
    Significant Figures
    Range (approx.)
    float
    System.Single
    32-bit single precision floating point
    7
    plus & minus 1.5 X 10-45 to ±3.4 X 1038
    double
    System.Double
    32-bit single precision floating point
    15/16
    plus & minus 5.0 X 10-3245 to ±3.4 X 10308

    Decimal Type

    Name
    CTS Type
    Description
    Significant Figures
    Range (approx.)
    decimal
    System.Decimal
    128-bit high precision decimal notation
    28
    plus & minus 1.0 X 10-28 to ±7.9 X 1028

    Boolean Type

    Name
    CTS Type
    Values
    bool
    System.Boolean
    true and false

    Character Type

    Name
    CTS Type
    Values
    char
    System.Char
    Represents a single 16-bit (Unicode) character)

    C# supports two predefined Reference Type

    Name
    CTS Type
    Values
    object
    System.Object
    The root type, from which all other types in the CTS derive (including value type)
    string
    System.String
    Unicode character string

    In .NET Microsoft has divided data types in two parts:
    1.  Value Type (Fixed in size)
    2.  Reference Type (Not fixed in size)
    In application context, value types are stored in stack but reference types are stored in managed heap.  

    Value Type

    • Value types are fixed in size.
    • Value types are made in system stack.
    • Actual values of data are stored in stack.
    • If you assign a value of a variable to another it will create two copies.
    All primitive data type except string and object are example of value types.
    Object is a super type. It can store any type and any size of data. Object is called super type because it helps in inheritance.
    struct and enum are value type.
    Note: Stack is an operation entity (LIFO) i.e. it is fixed in size.  

    Reference Type 

    • Reference types are not fixed in size.
    • They are maintained in system managed heap but it also uses stack to store reference of heap.
    • Two primitive types (string and object) and non-primitive data types (class, interface & delegate) are examples of reference type.
    CLR manages heap (large memory area). Heap address is accessed from stack. In reference type reference is used for processing using both managed heap and stack (operational entity).


No comments:

Post a Comment