Why does constructor not required in structure ?
Why does GC don't remove structures ?
Why does constructor not required in structure ?
Why does GC don't remove structures ?
Structure is a value type so it is not managed by GC. Structs can declare constructors, but they MUST take parameters. Copies of structs are created and destroyed automatically by the compiler, so a default constructor is unnecessary
A structure is a value type, that means, whenever you access it, or pass it along, its value is passed. ("copied")
on the other hand, classes are reference types. that if you pass that along, only the reference to it is passed (so both are now using the same object)
as you handle classes, and their instances as references, the GC has to check, if all references are already collected. that is not needed in value types, as they can only have one reference. that means, if the underlying object is collected, these are collected automatically.