Page 38 - DCAP312_WEB_TECHNOLOGIES_II
P. 38
Web Technologies-II
Notes The unified type system is enhanced by the ability to convert value types to reference types
(boxing) and likewise to convert certain reference types to their corresponding value types
(unboxing):
object boxedInteger = 97;
int unboxedInteger = (int)boxedInteger;
The built in C# type aliases and their equivalent .NET Framework types follow:
Integers
C# Alias .NET Type Size (bits) Range
Sbyte System.SByte 8 –128 to 127
Byte System.Byte 8 0 to 255
Short System.Int16 16 –32,768 to 32,767
Ushort System.UInt16 16 0 to 65,535
Char System.Char 16 A unicode character of code 0 to 65,535
Int System.Int32 32 –2,147,483,648 to 2,147,483,647
Uint System.UInt32 32 0 to 4,294,967,295
Long System.Int64 64 –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
Ulong System.UInt64 64 0 to 18,446,744,073,709,551,615
Floating-point
C# Alias .NET Type Size (bits) Precision Range
Float System.Single 32 7 digits 1.5 × 10-45 to 3.4 × 10 38
double System.Double 64 15-16 digits 5.0 × 10to 1.7 × 10 308
decimal System.Decimal 128 28-29 decimal 1.0 × 10to 7.9 × 10 28
places
Other Predefined Types
C# Alias .NET Type Size (bits) Range
bool System.Boolean 32 True or false, which are not related to any integer
in C#.
object System.Object 32/64 Platform dependant (a pointer to an object).
string System.String 16 * length A unicode string with no special upper bound.
The name “C sharp” was inspired by musical notation where a sharp indicates
that the written note should be made a semitone higher in pitch. This is similar
to the language name of C++, where “++” indicates that a variable should
be incremented by 1.
Write a program to show the example of boxing and unboxing.
Using unboxing can be cause of decreasing or loss the value of data.
32 LOVELY PROFESSIONAL UNIVERSITY