I have an immutable struct and would like to keep it immutable, but also allow schematics like var p2 = p1.v = 3
. I thought that the following might work, but it appears not:
public struct Number {
readonly int n;
public int N {
get{ return n; }
set{ return new Number(value); }
}
public Number(int newN) {
n = newN;
}
}
Is there any way to get var p2 = p1.v = 3
or var p2 = (p1.v = 3)
to work?
No, there is no syntax like this that will work. Setters are, well, setters, not a way to get something.