Pages

Thursday, May 9, 2013

datatype in c#

The two fundamental data types in C# are value types and reference types

Value Types

Value type variables can be assigned a value directly. They are derived from the class System.ValueType.
The value types directly contain data. Some examples are int, char, float, which stores numbers, alphabets and floating point numbers respectively. When you declare an int type, the system allocates memory to store the value.
Note: value types are stored on the stack when the value is a local variable
examples:
1.byte(1 byte)
2.sbyte(1 byte)
3.char(2 byte)
4.short(2 byte)
5.ushort(2 byte)
6.int(4 byte)
7.uint(4 byte)
8.flout(4 byte)
9.long(8 byte)
10.ulong(8 byte)
11.double(8 byte)
12.decimal(16 byte)
...etc

Reference Types

The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.
Note: Reference types are created on the Heap
example:
  • String
  • All arrays( even if their elements are value types)
  • Class 
  • Delegates
  • interface
  • object




1 comment: