Skip to content

Instantly share code, notes, and snippets.

@rstropek
Last active June 6, 2021 06:47
Show Gist options
  • Save rstropek/748161e42d7a0b840f1a86c03f2715ce to your computer and use it in GitHub Desktop.
Save rstropek/748161e42d7a0b840f1a86c03f2715ce to your computer and use it in GitHub Desktop.
using System;
var p = new Person("Foo", "Bar", 42);
// The following line does not work because records are immutable
// p.LastName = "Baz";
Console.WriteLine(p.FirstName);
var b = new Product("Bike", "Mountainbike", 499m);
Console.WriteLine(b.Name);
// Usual syntax, results in record classes (=reference types)
record Person(string FirstName, string LastName, int Age);
// New syntax "record class"
record class Product(string Category, string Name, decimal Price);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment