Explain the Difference between value and reference type.

Answer Posted / suhasini suresh

Reference types are stored on the run-time heap; they may
only be accessed through a reference to that storage. This
allows the garbage collector to track outstanding
references to a particular instance and free the instance
when no references remain. A variable of reference type
always contains a reference to a value of that type or a
null reference. A null reference refers to nothing; it is
invalid to do anything with a null reference except assign
it. Assignment to a variable of a reference type creates a
copy of the reference, not a copy of the value being
referenced.

Value types are stored directly on the stack, either within
an array or within another type. When the location
containing a value type instance is destroyed, the value
type instance is also destroyed. Value types are always
accessed directly; it is not possible to create a reference
to a value type. Prohibiting such a reference makes it
impossible to refer to a value class instance that has been
destroyed. A variable of a value type always contains a
value of that type. Unlike reference types, the value of a
value type cannot be a null reference, nor can it reference
an object of a more derived type. Assignment to a variable
of a value type creates a copy of the value being assigned.

Is This Answer Correct ?    10 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is stored procedure ? how we use it in .NET ?

609


When a Static Constructor called in .NET?

615


Do you know what is garbage collector?

579


How to prepare parametrized (with more than one parameters) crystal report. Please tell me the code procedure, if any body can?

540


Different levels of priority provided by .net.

599






What is the difference between boxing and unboxing?

547


Difference abstract class and interface in .net?

610


Explain .net framework overview?

595


What is the difference between reference type and value type?

519


Tell us what is a sealed class?

559


How to debug failed assembly binds?

608


Is .net core free?

578


What is STA in .NET?

649


What is class library in .net

606


What is meant by globalization?

573