3 ms·
> here's nothing preventing the method call from mutating it. There is, the class could be immutable. public class Vector { public readonly in
by louthy 10y ago
> here's nothing preventing the method call from mutating it.
There is, the class could be immutable.
public class Vector
{
public readonly int X;
public readonly int Y;
public Vector(int x, int y)
{
X = x;
Y = y;
}
public Vector With(int? X = null, int? Y = null) =>
new Vector(X ?? this.X, Y ?? this.Y);
}
I believe record-types are proposed for the next release of C#.
- benaadams 10y agoMutable class with immutable struct wrapper would be better on allocations; then pass in the struct wrapper.