using System;
var p1 = new Point1(1, 1);
var str1 = p1.ToString();
//str1 is '(1, 1)'
Console.WriteLine($"str1 is '{str1}'");
var p2 = new InhPoint1(2, 2);
var str2 = p2.ToString();
//Method is not inherited
//str2 is 'InhPoint { X = 2, Y = 2 }'
Console.WriteLine($"str2 is '{str2}'");
var p3 = new InhPoint2(3, 3);
var str3 = p3.ToString();
//str3 is '(3, 3)'
Console.WriteLine($"str3 is '{str3}'");
record Point1(int X, int Y) {
public override string ToString() {
return $"({X}, {Y})";
}
}
record InhPoint1 : Point1 {
public InhPoint1(int X, int Y) : base(X, Y) { }
}
record Point2(int X, int Y) {
//in version 10:
public sealed override string ToString() {
return $"({X}, {Y})";
}
}
record InhPoint2 : Point2 {
public InhPoint2(int X, int Y) : base(X, Y) { }
}