C struct in C#

G

Guest

last post sent prematurely.

This didn't work. Compile error says I can't have instance field
initializers in structs

[StructLayout(LayoutKind.Sequential)]
public struct cdVersionInfo
{
public int Size;
public char[] = new char[32];
}

Thanks in advance.
 
N

Nicholas Paldino [.NET/C# MVP]

Bob,

That is right. You have to define it without the "new char[32]".

Rather, you should define a factory that would do this for you, or add a
parameter that will take the byte array and assign it to the field.

Hope this helps.
 
M

Michael Groeger

Bob,

another way is to write a Constructor for the struct and do initialization
there.

Regards,
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top