It isn't boxed, but the data will be a copy of the original, and every time you get the data out, it will copy again. This tends to make it easy to lose changes. As such, you should aim to not write mutable structs. Unless MyStruct
actually represents a unit-of-measure (or similar), make it a class. And if it is a measure, make it immutable (no public settable members).
And either way, don't expose fields! Use properties ;-p
For example:
struct MyStruct {
public MyStruct(int val1, decimal val2) {
this.val1 = val1;
this.val2 = val2;
}
private readonly int val1;
private readonly decimal val2;
public int Val1 {get {return val1;}}
public decimal Val2 {get {return val2;}}
}
Or alternatively (C# 3.0):
struct MyStruct {
public MyStruct(int val1, decimal val2) : this() {
Val1 = val1;
Val2 = val2;
}
public int Val1 {get; private set;}
public decimal Val2 {get; private set;}
}