Structs are an extremely broken feature which any sane and competent programmer should completely avoid:
Are copied by value, leading to unexpected behavior, e.g. arrayOfStruct[1].Field = 1 is fine but listOfStruct[1].Field = 1 is not
Can sometimes be created in an invalid state because the constructor was not called (runtime, you had one job!)
Do not support inheritance, which contradicts the OOP priciples on which C# is built
Introduce a lot of keywords like ref, readonly and so on, that blow up the language grammar and put cognitive load on the programmer
The readonly modifier does not even guarantee stuff inside being readonly, as you can put a List<T> into a readonly struct and add elements to it at any point
The suggested fix will be to change all struct declaration to class.
Structs are an extremely broken feature which any sane and competent programmer should completely avoid:
arrayOfStruct[1].Field = 1
is fine butlistOfStruct[1].Field = 1
is notref
,readonly
and so on, that blow up the language grammar and put cognitive load on the programmerreadonly
modifier does not even guarantee stuff inside being readonly, as you can put aList<T>
into a readonly struct and add elements to it at any pointThe suggested fix will be to change all
struct
declaration toclass
.