Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

basic difference between value types and reference types [duplicate]

Possible Duplicate:
What are the differences between value types and reference types in C#?

what are the basics differences between values types and rereference types

like image 849
Raghav Avatar asked Mar 31 '11 14:03

Raghav


People also ask

What is the difference between value types and reference types?

There are two kinds of types in Visual Basic: reference types and value types. Variables of reference types store references to their data (objects), while variables of value types directly contain their data.

What is difference between value type and reference type Swift?

In Swift there are two categories of types: value types and reference types. A value type instance keeps a unique copy of its data, for example, a struct or an enum . A reference type, shares a single copy of its data, and the type is usually a class .

What is the difference between a value model and a reference model of variables?

Value model: Each variable refers to a single value. Assignment means copying from the r.h.s. to the l.h.s. This is the default in C/C++ and SPL. Reference model: Each variable refers to an object in memory.

What is the difference between a value type and reference type variable Can you give an example of each?

All fundamental data types, Boolean, Date, structs, and enums are examples of value types. Examples of reference types include: strings, arrays, objects of classes, etc.


1 Answers

Consider two variables:

SomeReferenceType x;
SomeValueType y;

The value of x is a reference - it will either be null or a reference to an object which is itself an instance of SomeReferenceType or a derived class. The value of x is not, in itself, the object.

The value of y is the data itself - if SomeValueType has three fields, the value of y will directly contain those fields.

That's a very brief summary - see Eric Lippert's blog post about value types and my article for more information. (You might also be interested in my article about parameter passing which is related, but not quite the same.)

like image 144
Jon Skeet Avatar answered Sep 28 '22 09:09

Jon Skeet