I am currently doing some reading on structs and came across an example of structs being used with attributes. In the example the struct attribute being used is [FieldOffset(0)] which it says makes sure the fields are stored in the same piece of memory.
What is the advantage(s) or disadvantage(s) of this?
Also why would one want to use FieldOffsetAttribute to put the fields in different parts of memory?
This is used to control the exact offset in memory of the members of the struct. It’s sometimes used in C# when you want to represent a native (C++) struct in the context of a P/Invoke call.
In C# there is no things such as structs unions, so you have to use
FieldOffsetValueAttribute.I recommend you to read the following article.