Skip to content

Instantly share code, notes, and snippets.


richlander/Program.cs Secret

Last active Sep 12, 2020
What would you like to do?
Records and nullability
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Author lord = new Author("Karen Lord")
Website = "",
RelatedAuthors = new()
new Book[]
new Book("The Best of All Possible Worlds", 2013, lord),
new Book("The Galaxy Game", 2015, lord)
new Author[]
new ("Nalo Hopkinson"),
new ("Ursula K. Le Guin"),
new ("Orson Scott Card"),
new ("Patrick Rothfuss")
Console.WriteLine($"Author: {lord.Name}");
Console.WriteLine($"Books: {lord.Books.Count}");
Console.WriteLine($"Related authors: {lord.RelatedAuthors.Count}");
public record Author(string Name)
private List<Book> _books = new();
public List<Book> Books => _books;
public string? Website {get; init;}
public string? Genre {get; init;}
public List<Author>? RelatedAuthors {get; init;}
public record Book(string name, int Published, Author author);
<Project Sdk="Microsoft.NET.Sdk">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment