Created
November 13, 2020 01:39
-
-
Save jonschoning/3fbad75bee079cf7f864158d08494413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
static void Run() | |
{ | |
Employee foo = new Employee("Aysha", "Stein", "1234"); | |
Person bar = (Person)foo with { FirstName = "John", LastName = "Doe"}; | |
Console.WriteLine($"foo: {foo}"); | |
Console.WriteLine($"bar: {bar}"); | |
// Expected Output: | |
// 1) foo: Employee { FirstName = Aysha, LastName = Stein, EmployeeNumber = 1234 } | |
// bar: Employee { FirstName = John, LastName = Doe, EmployeeNumber = 1234 } | |
// 2) foo: Employee { FirstName = John, LastName = Doe, EmployeeNumber = 1234 } | |
// bar: Employee { FirstName = John, LastName = Doe, EmployeeNumber = 1234 } | |
// 3) foo: Employee { FirstName = Aysha, LastName = Stein, EmployeeNumber = 1234 } | |
// bar: Person { FirstName = John, LastName = Doe } | |
// 4) foo: Employee { FirstName = John, LastName = Doe, EmployeeNumber = 1234 } | |
// bar: Person { FirstName = John, LastName = Doe } | |
} | |
Run(); | |
public record Person(string FirstName, string LastName); | |
public record Employee(string FirstName, string LastName, string EmployeeNumber) : Person(FirstName, LastName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment