faqts : Computers : Programming : Languages : C# : .NET Framework

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 5 people (80%) answered Yes
Recently 4 of 5 people (80%) answered Yes

Entry

What are the two types of datatypes in .NET?

Jun 18th, 2005 18:32
Krishnan .L.N, Suresh Kumar.G


The two different data types are 
1)value based data type
2)reference based data type
In value based data type,
the value is stored in the stack...
For e.g, consider int i=3;
here the value 3 is stored in the stack..The value i is removed from 
the memory as soon it gets out of the scope..
e.g
public void getvalue()
{
int j=9;
j++;
}// j loses it value here...
The egs for value based data types are int,float etc...
In reference based data type,
the internal value of the object is stored in the heap..
Classes and interfaces are examples for reference based data type..
It is removed from the memory once the garbage collector performs the 
deletion...
It is interesting to see that we can convert between value and 
reference based data type..
This process is known as Boxing,which converts an value based data 
type to a reference based data type and for UnBoxing it is vice-versa.
E.g,
int i=3;
object obji=(object)i; //Boxing
int i=(int)obji;   //Unboxing
Hope it was useful to u..For any suggestions contact my email id
krishnan.srikanth@gmail.com