Mutating value types – Part 2
In the previous blog post, we found that mutating a struct inside a class works if the struct is declared as a field, but doesn’t work if it is declared as a property. The reason is fairly obvious – if struct fields also returned a copy, then there wouldn’t be any way of mutating the instance at all, even from within the declaring class. 1: struct S 2: { 3: public int X; 4: } 5: 6: class C 7: { 8: public S S; 9: 10: void SetX() 11: { 12: this.S.X = 1; // Won’t work if this.S … Continue reading Mutating value types – Part 2