Tuesday, 15 April 2014

attributes - what is advantage of StructLayoutAttribute in C# struct -



attributes - what is advantage of StructLayoutAttribute in C# struct -

i came across utilize structlayoutattribute dont know how helpful use. have struct

[structlayout(layoutkind.sequential)] public struct xydata { public int x; public int y; public xydata(int x, int y) { this.x = x; this.y = y; } }

applying attribute structlayoutattribute help us?

as specified in structlayoutattribute c# using sequential struct. technically there no impact of adding attribute:

c#, visual basic, , c++ compilers apply sequential layout value structures default.

you can safely add together value struct in c# code explicitly document intent, optional.

if emiting construction or using il straight need specify it.

note classes need specify sequential straight if find need particular layout of fields in class.

c# attributes

No comments:

Post a Comment