Why does LayoutKind.Sequential work differently if a struct contains a DateTime field?

后端 未结 6 2368
名媛妹妹
名媛妹妹 2020-12-05 07:17

Why does LayoutKind.Sequential work differently if a struct contains a DateTime field?

Consider the following code (a console app which must be compiled with \"unsaf

6条回答
  •  醉话见心
    2020-12-05 07:59

    To answer my own questions (as advised):

    Question: "Does this behaviour have any ramifications when doing interop with C/C++ structs that use the Com DATETIME type?"

    Answer: No, because the layout is respected when using Marshalling. (I verified this empirically.)

    Question "Can anyone provide an explanation?".

    Answer: I'm still not sure about this, but since the internal representation of a struct is not defined, the compiler can do what it likes.

提交回复
热议问题