WHAT IS DIFFERENCE BETWEEN VALUE TYPES AND REFERENCE TYPES IN VB.NET OR C# (VALUE TYPES VS REFERENCE TYPES)?

Amit Singh

Total Post:565

Points:2825
Posted by  Amit Singh
VB.Net 
 1574  View(s)
Ratings:
Rate this:
  1. Amit Singh

    Post:565

    Points:2825
    What is difference between Value types and Reference types in VB.NET or C# (Value types VS Reference types)?

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!