Home

valuetype

A valuetype is a category of types in programming where instances store their data directly, rather than as references to separate heap-allocated objects. In languages that distinguish value types from reference types, operations on valuetypes typically copy the entire value, giving each variable its own independent data.

In the .NET ecosystem, value types are implemented as structs or enums and derive from System.ValueType. They

Common examples include primitive numeric types such as int and double, booleans, and user-defined types declared

Advantages of valuetypes include predictable memory usage and copying semantics, which can reduce the overhead of

In metadata terms, the Common Language Infrastructure signals value types with the valuetype designation in type

are
stored
inline
in
their
containing
storage
(on
the
stack
or
embedded
within
other
objects)
rather
than
on
the
managed
heap.
Assigning
or
passing
a
value
type
copies
its
data,
implementing
value
semantics.
If
a
value
type
needs
to
be
treated
as
an
object,
it
can
be
boxed
into
a
reference
type;
unboxing
retrieves
the
original
value.
as
structs
or
enums.
Other
languages
adopt
value-type
semantics
in
various
ways:
Swift
and
Go
treat
structs
as
value
types;
C++
commonly
uses
value
types
for
objects
allocated
on
the
stack
or
embedded
in
other
objects;
Java
separates
primitive
types
from
objects,
with
primitives
behaving
as
value-like
types
even
though
they
are
not
classes.
garbage
collection
and
avoid
shared
mutable
state.
Disadvantages
include
the
potential
cost
of
copying
large
valuetypes
and
the
need
for
boxing
when
passing
to
APIs
that
expect
a
reference
type.
Practical
guidance
is
to
use
valuetypes
for
small,
immutable,
or
insignificantly
sized
data,
and
to
prefer
reference
types
for
large,
polymorphic,
or
mutable
data
structures.
signatures,
distinguishing
them
from
classes
that
are
reference
types.