Records
code:records.cs
class Point{
public readonly float X;
public readonly float Y;
public Point With(float x = this.X, float y = this.Y)
=> new Point(x, y);
}
var p = new Point(1, 2);
var q = p.With(y: 3);
code:record.cs
// こういうコードが山ほど書かれる
class Point {
public readonly float X;
public readonly float Y;
public Point(float x, float y) {
X = x;
Y = y;
}
bool Equals(Point other) => (X, Y) = (other.X, other.Y);
int GetHashCode() => ....
}
// recordで削減できる.
record Point(float X, float Y); // プライマリコンストラクタ
docs
asRagi.icon