The answer is two-part. First, you're returning a new instance on every call (=>
), rather than returning a stored instance (=
). In other words, what you seem to want is this:
// caveat: you can't use "this" before the constructor is called
// you'll have to initialize this property inside the constructor instead
public MyStruct Struct { get; } = new MyStruct(this);
However, struct
s are copied by value, so even if you write it correctly, you'll still get a new instance every time. Either use a class
, or use ref struct
instead, like this:
MyStruct myStruct;
public ref MyStruct Struct => ref myStruct;
The above will let you modify the internal structure as you would expect.