C# Struct No Parameterless Constructor? See what I need to accomplish

前端 未结 6 567
既然无缘
既然无缘 2020-12-15 08:06

I am using a struct to pass to an unmanaged DLL as so -

[StructLayout(LayoutKind.Sequential)]
        public struct valTable
        {
            public byt         


        
6条回答
  •  伪装坚强ぢ
    2020-12-15 08:54

    You can use a fixed size buffer - which I suspect you really want anyway, so as to get the data "inline" in the struct (rather than a reference to an array elsewhere).

    public fixed byte name[24];
    

    You'll need to declare the struct as unsafe as well though.

    Note that any "solution" which requires calling a static method or providing any kind of custom constructor will fail with your explicit goal of being able to create an array of these structs.

提交回复
热议问题