Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is the Difference between value and reference type?

Answer Posted / vishvam

What is the difference between value type and reference
type? Can a value type contain NULL values?

In simple words, all value based types are allocated on the
stack, while all reference based types are allocated on the
heap. What does this mean? A value type contains the actual
value. A reference type contains a reference to the value.
When a value type is assigned to another value type, it is
copied. When a reference type is assigned to another
reference type, a reference is assigned to the value.

By saying stack, we mean things are kept one on top of the
other. We keep track of each value at the top. By saying
heap, we mean things are kept in a mashed order. We keep
track of each value by its address, that is referenced by a
pointer to it.

All value types are implicitly derived from
System.ValueType. This class actually overrides the
implementation in System.Object, the base class for all
objects which is a reference type itself.

Data types like integers, floating point numbers, character
data, Boolean values, Enumerations and Structures are
examples of Value Types. Classes, Strings, Arrays are
examples of Reference Types.

A value type may not contain NULL values. Reference types
may contain NULL values.

It is not possible to derive new types from Value Types.
This is possible in Reference types. However, Value Types
like Structures can implement interfaces.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between first and firstordefault?

895


What is the difference between selection and projection?

849


write a C# Program add two matrix ?

991


Can enum be null c#?

987


Why is static constructor called first?

885


Explain the difference between // comments, /* */ comments and /// comments?

869


If a.equals(b) is true then a.gethashcode & b.gethashcode must always return same hash code.

991


Contrast between an interface and abstract class?

959


What is boxing and unboxing in c#?

845


What are custom exceptions? Why do we need them?

961


Can the nested class access, the containing class. Give an example?

866


In which format you can pass the value in the sleep function?

910


What language is arduino?

976


what is inheritance and an example in vb.net and c# of when you might use it?

930


What are primitive types in c#?

966