Saturday 26 April 2014

C# Data Types

In C#, variables are categorized into the following types:
  • Value types - contain data.
  • Reference types - contain a reference to the variables.
  • Pointer types - store the memory address of another type.
     
    Value types –Available value types are: Integral Types, Float point types, Decimal, char, Boolean
    Integral Types
Type
No of bit
Signed
Range
Default
sbyte
8
yes
-128 to 127
0
byte
8
no
0 to 255
0
short
16
yes
-32,768 to 32,767
0
ushort
16
no
0 to 65,535
0
int
32
yes
-2147483648 to 2147483647
0
uint
32
no
0 to 4294967295
0
long
64
yes
-923372036854775808 to 9223372036854775807
0L
ulong
64
no
0 to 18446744073709551615
0
 
Floating-point and Decimal Types
Type
No of bit
Range
Default
float
32
-3.4 x 1038 to + 3.4 x 1038
0.0F
double
64
(+/-)5.0 x 10-324 to (+/-)1.7 x 10308
0.0D
Decimal (mainly used for bank)
128
(-7.9 x 1028 to 7.9 x 1028) / 100 to 28
0.0M
 
Character and Boolean types
Type
No of bit
Range
Default
char
16
U +0000 to U +ffff
'\0'
Bool
8
True/ false
False
 
Note:
  • sizeof(type) yield the size of an object
     
Reference typesAvailable Reference types are object, dynamic and string.
Object Type- Object types can be assigned values of any other types. However, before assigning values, it needs type conversion.
Boxing - Value type is converted to object type
Unboxing - Object type is converted to a value type
int i = 123;      // a value type
object var = i;     // boxing
int j = (int)var;  // unboxing
 
Dynamic Types -Any type of value is stored in the dynamic data type variable. Only at runtime type checking of theses variable take place.
Eg dynamic d = 10;
 
String Type-Any string values can be assigned to a variable
String str = "Hello";
 
Pointer Type -Store the memory address of another type.
Eg int* var;

No comments:

Post a Comment