=> structs are value types that
can contain data and functions.
=> structs are value types and
do not require heap allocation.
=> structs directly store their
data in the struct, classes store a
reference to a dynamically allocated bject.
=> structs are useful for small
data structures.
=> structs can affect
performance
=> Constructors are
invoked with the new operator, but that does not allocate memory on the heap
=> A struct constructor simply
returns the struct value itself
(typically in a temporary location on the stack), and this value is then copied
as necessary
=> With classes,
multiple variables may have a reference to the same object
=> It is possible for
operations on one variable to affect the object referenced by the other
variable.
=> With structs, the variables each
have their own copy of the data, and it is not possible for operations on one
to affect the other.
=> structs do not
support user-specified inheritance, and they implicitly inherit from type
object
Comments
Post a Comment