What is the Difference between value and reference type?

Answer Posted / saransony

C# provides a set of different data types. The data types
in C# are divided into two categories – Value Types and
Reference Types. Although there is a third data type –
pointers, Pointers can only be used in unsafe code.
A variable that is a value type, stores the data, while a
variable of a reference type stores a reference to the
data. Both Value Types and Reference Types have one
interesting thing in common – they both derive from System.
Object. This is interesting, because most other object-
oriented languages do not have this behavior.
Value Types
The value of value types is stored on the managed stack,
and can be used directly. This means that the value is
stored, and not a reference to the value. This also means
that each value type has its own copy of the data.
Reference Types on the other hand has a reference to the
data, and several variables can reference the same data.
Reference Types
In contrast to value types, the value of a reference types
is allocated on the heap. Another name for a reference
type, that you might be more familiar with, is an object.
Reference types stores the reference to the data, unlike
value types, that stores the value.
Links- http://www.programmersheaven.com/2/FAQ-CSHARP-
ValueRef-ValueType-Differences

http://msdn.microsoft.com/msdnmag/issues/1200/dotnet/
http://msdn2.microsoft.com/en-
us/library/2hf02550.aspx

http://dotnetsutra.blogspot.com/2007/10/difference-between-
value-type-and.html

Is This Answer Correct ?    22 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is better C# or VB.NET?

532


What are the different approaches of passing parameters to a method?

484


Explain dataadapter.update method in .net?

520


Explain streamreader/streamwriter class?

538


What is the use of 'using' statement in c#?

487






How does dependency injection work c#?

502


How long will it take to learn c sharp?

496


What is dll file in c#?

524


if a method is marked as protected internal who can access it?

570


Explain the different types of delegates used in c#.

514


How do destructors and garbage collection work in c#?

532


How can you write a class to restrict that only one object of this class can be created (Singleton class)?

519


Is hashset ordered c#?

503


What is the difference between ienumerable and icollection?

470


what is generics? can u explain 5 to 6 examples on generics that covers class,method,structure,list,delegates?

1450