Please enable JavaScript.
Coggle requires JavaScript to display documents.
02 Value types and other stuff (Struct types (Similarities with both…
02 Value types
and other stuff
Recap
Passing / assigning basic value types (int etc)
Passing / assigning reference types (objects from classes)
Reference types: reference to object is passed by value
but there is still only one copy of the object itself, so any
change to the contents of the object are seen by everyone
Struct types
Similarities with both classes and basic types
Have fields, properties, methods like class
But, when assigned / passed, clone is made
Also, structs are allocated on stack not heap
Can use new / constructor, but don't have to
Reasons for using struct
Full comparison with class (reference) types
Enum
data type
Like a struct without methods
Only contains constants
Automatically numbered at 1+, but can override
Using an enum as a collection of flags
HasFlag
method
Object
initialisation
Instantiate and set properties in one go via
... = new Xyz { A = ..., B = ..., C = ... };
Other stuff
Passing array as variable number of parameters
via the
params
keyword
Partial classes via
partial
keyword
Named parameters
Optional / default parameters
Arrays of arrays (jagged arrays)