A record
in C# 9.0 can inherit from another record
. This is one of the strong reasons why you should consider using record
over struct
.
var student = new Student() { FullName = "Wrishika Ghosh", Grade = "V" };
public record Person
{
public string FullName { get; set; }
}
public record Student : Person
{
public string Grade { get; set; }
}
You can even simplify it by using the positional approach via auto construct,
var student = new Student("Wrishika Ghosh", "V");
public record Person(string FullName);
public record Student(string FullName, string Grade) : Person(FullName);
Top comments (0)