Home > DeveloperSection > Interviews > What is difference between Value types and Reference types in VB.NET or C# (Value types VS Reference types)?

Posted on    November-16-2010 12:00 AM

 VB.Net VB.Net 
 1 Answer(s)
  1320  View(s)
Rate this:

Amit Singh

Total Post:565

Posted on    November-16-2010 1:00 AM

C# provides two types—class and struct, class is a referencetype while the other is a value type. Here is difference between Value typesand Reference types.
Value types directly contain their data which are either allocated on the stackor allocated in-line in a structure. Reference types store a reference to thevalue's memory address, and are allocated on the heap. With reference types, anobject is created in memory, and then handled through a separate reference—ratherlike a pointer.
Reference types can be self-describing types, pointer types, or interfacetypes. Primitive types such as int, float, bool and char are value types.
Variables that are value types each have their own copy of the data, andtherefore operations on one variable do not affect other variables. Variablesthat are reference types can refer to the same object; therefore, operations onone variable can affect the same object referred to by another variable.
Value types have a default implied constructor that initializes the defaultvalue. Reference types default to a null reference in memory.
Value types derive from System.ValueType. Reference types derive fromSystem.Object.
Value types cannot derive a new type from an existing value type, except forstructs. Reference types can derive a new type from an existing reference typeas well as being able to implement interfaces.

Don't want to miss updates? Please click the below button!

Follow MindStick