Last active
December 23, 2020 14:47
-
-
Save crgrieve/77350c24c29b070ca7f2fa515dfc24b5 to your computer and use it in GitHub Desktop.
C# 9 init properties using "with"
This file contains hidden or 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; | |
var glasgowMeetup = new Meetup() { | |
City ="Glasgow", | |
Topic = ".Net" | |
}; | |
var edinburghMeetup = glasgowMeetup with { City="Edinburgh" }; | |
glasgowMeetup.Topic = "Umbraco"; | |
Console.WriteLine(glasgowMeetup); | |
Console.WriteLine(edinburghMeetup); | |
public record Meetup | |
{ | |
public string City { get; init; } | |
public string Topic { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment