Is LayoutKind.Sequential ever needed with VB (or C#)

  • Thread starter Thread starter SamSpade
  • Start date Start date
S

SamSpade

I see <StructLayout(LayoutKind.Sequential)> before a Structure Definition in
many examples.

However, the doc says:
To reduce layout-related problems associated with the Auto value, C#, Visual
Basic .NET, and C++ compilers specify Sequential layout for value types.

I think a Structure is a value type. Correct??
Also in c# ??


If so, does the Doc note mean that there is no reason to add
<StructLayout(LayoutKind.Sequential)>

Thanks
 
If so, does the Doc note mean that there is no reason to add
<StructLayout(LayoutKind.Sequential)>

Right, you don't have to put that on structs unless you want to set
some other property of the StructLayout attribute (CharSet for
example).



Mattias
 
You will need to do it when using InterOp and passing your strucutres
to native code.

hth
Richard
 
Thanks for sharing but as I now understand it, it is not needed because it
is the default for the compilers
 
Ive found you do. I often use it for precisely this purpose. I find it does
the trick quite nicely.

;)

hth
Richard

You don't. LayoutKind.Sequential is the default attribute assumed by
the runtime. If you aren't going to be changing anyother properties of
the attribute - then you don't need it. Of course, I usually put it on
anyway - habbit I guess.
 
Back
Top