(The question title has been updated to reflect that the struct must eventually be converted using the Marshal class.)
I have some structs that by design will always contain fixed values. For example, let's assume a struct that contains two bytes:
public struct ExampleStruct {
public byte b0;
public byte b1;
}
How can I update that implementation so that b0 always holds the value 0 and b1 always holds the value 1? I've tried various combinations of const, readonly, and constructors, all with no luck.
Ideally I'll be able to use it like this and have the bytes initialized to the correct values:
ExampleStruct es = new ExampleStruct();
Note that I eventually need to convert the struct to a byte[] using the Marshal class so it can be sent to a driver. I have verified that this prohibits the use of properties within the struct, as those properties are ignored during the Marshal to byte[]. Also note that in this case Marshal != Serialize, as I need the actual struct byte contents and not a serialized string that can be deserialized later.