what is the difference between reference type and value type?
vinod kumar 0
value type : storage will be on stack memory
Reference type: storage will be on heap memory
stack memory will be allocated by the compiler towards an application ,this
doesn't supprt dynamic creation and destruction.
It is recommended for string small amount of data for faster access.
Runtime will be allocate heap memory.This will support dynamic allocation and destruction.
This memory supports hiearchial representation of data i.e inheritance process.
This memory is recommended for large storage of data.
Value type :Value type is Nothing but it can store the Values in Stack Memory .ex: int a = 100;here a =100 valu can store in Stack memory.Value type Does not Allowed null values.structure is value type ,int,byte,enum etc.Referece Type :Referece Type is Nothin But stord the value in Heap memory.Ex:public class A {public void Hi(){Console.WriteLine("Hi How r u");}}public static void main(){A a= new A();//here "a" refferece values is stor in Heap Memory.a.hi();}}Reference type will be Allowed Null values.ex:class,Object,interface etc.
Differences between Value types and Reference types:Value type holds the data directlyReference type points to the location that holds the data.Examples of value type variables: byte, decimal, float, int, structsExamples of reference type variables: string, class, delegate, interfaceValue type cannot contain null value Reference type can contain null value.Value type variables are stored on stack. Reference type variables are stored on heap.A new type cannot be derived from value type. A new type can be derived from reference type.