[Structlayout (layoutkind. Sequential)] is a structure Sorting Problem;
First, we will introduce the differences between struct and classes: the class is passed by reference, and the struct is passed by value.
Enter the subject:
Struct is composed of several members. There are two types of layout:
1. Sequential: sequential layout, such
Struct S1
{
Int;
Int B;
}
By default, A is first arranged in the memory and then B.
That is, if you can get the address of a, and the address of B, the difference is an int type length, 4 bytes
[Structlayout (layoutkind. Sequential)]
Struct S1
{
Int;
Int B;
}
This is the same as the previous one, because the default memory arrangement is sequential, that is, sequential arrangement by members.
2. explicit, precise Layout
You need to use fieldoffset () to set the location of each member.
In this way, the function of a public body similar to C can be implemented.
[Structlayout (layoutkind. explicit)]
Struct S1
{
[Fieldoffset (0)]
Int;
[Fieldoffset (0)]
Int B;
}
In this way, A and B are in the same memory address.
Okay, it's easy to understand.