Skip to content

Instantly share code, notes, and snippets.

@crgrieve
Last active December 23, 2020 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crgrieve/77350c24c29b070ca7f2fa515dfc24b5 to your computer and use it in GitHub Desktop.
Save crgrieve/77350c24c29b070ca7f2fa515dfc24b5 to your computer and use it in GitHub Desktop.
C# 9 init properties using "with"
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