I have:
A struct
struct Data { int a; int b; }
A class containing the struct
class Packet {
Data DataStruct;
}
When I now instantiate my class, I assume that the struct lives on the heap.
If I now do something like
SomeClass.Process(new Packet().DataStruct);
SomeClass.Process(new Packet().DataStruct.a);
will it be passed as value?
If not, is there any reason not to make the struct into a class instead?
structs are value types, so it will be passed asvalue.Classesarereferencetypes.Everything will be passed as
valueunlessoutorrefis specified.