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
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.
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 .
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.
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With