Wednesday, January 4, 2017

                                      C# Type System 

C# Type System Contains Three Types  :

  1. Value Types
  2. Reference Types
  3. Pointer Types
  1. When we convert Value Type to Reference Type is called Boxing.
  2. When we convert Reference Type to Value Type is called Un-boxing.



Example : Boxing

Int  value =12  ;  Integer Type Of Variable

Object obj= value ; //Boxing

1-In the Example : 
The first line I have created a Value Type integer variable (Value) and assigned  a value.

2- In the Example :
The second line I have created and instance of Object class and assign the value of integer variable (value) to obj.
In this example we  converted Value Type In to  Reference type  .This type of operation called Boxing.

Example : UnBoxing

int value=20;

Object obj=value ; //Boxing

int val1=(int)obj;  //UnBoxing


1-In the Example : 
The first line I have created a Value Type integer variable (Value) and assigned  a value 20 .

2- In the Example :
The second line I have created and instance of Object class and assign the value of integer variable (value) to obj. Called Boxing

3. In third line shows extracts the value type from the object. This is converting a value of a reference type into a value type. This is called UnBoxing
    In this example we  converted  Reference type In to Value Type  .This type of operation called UNBoxing.                                               

    No comments:

    Post a Comment