Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the difference between Value and Reference Types and its Significant in programming ? I'm totally new to object oriented programming paradigm ! An explanation with an example would be much helpful....

Thanks in Advance !!
Posted

Numeric data types such as integers, floats, etc, boolean, enumerations and user defined structures are value types.

Classes, interfaces and delegates are reference types.

An instance of the reference type, called an object, is allocated and managed on the Garbage Collection heap, and all reads, writes, and sharing of it are performed through a reference (i.e., a pointer indirection).

A value type instance, called a value, on the other hand, is allocated inline as a sequence of bytes, the location of which is based on the scope in which it is defined
 
Share this answer
 
Comments
Kumar Bhandari 19-Dec-11 4:34am    
Dude...I want an explanation not a definition !! :(
TorstenH. 20-Dec-11 10:00am    
good answer.
@ Kumar-Dude: Please learn your basics.
Start here: http://docs.oracle.com/javase/tutorial/java/concepts/ to find out what a class, an Interface and a variable is and where the difference is.
hi dude,

Basically data types can be classified into two basic types.

1)Value type
2)Reference type.


value types directly holds its value but reference type not.

int myVar = 10;


when the above statement executes, CLR allocates a stack with address "myVar". The stack "myVar" will hold your value 10.

String myvar ="Hello world";


When the above code executes, CLR will allocates a stack with address "myvar" but it will not directly holds the value("hello world"). instead of tis, CLR will store the actual value("hello world") in heap and stores the heap address in the stack "myVar".
 
Share this answer
 
v4
Comments
Kumar Bhandari 22-Dec-11 4:57am    
Thanks dude.... !! really appreciated :)
When a lot of people have explained that in very detailed manner why should we repeat those words. So spend some time and read these resources :

http://msdn.microsoft.com/en-us/library/0f66670z%28v=vs.71%29.aspx[^]

http://www.developerfusion.com/article/4697/parameter-passing-in-c/[^]

http://www.albahari.com/valuevsreftypes.aspx[^]

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900