Skip to content

Instantly share code, notes, and snippets.

Last active June 14, 2018 06:43
What would you like to do?
C# 8 Book Class
class Book
public string Title { get; }
public string Publisher { get; }
public string? Isbn { get; }
public Book(string title, string publisher, string? isbn)
=> (Title, Publisher, Isbn) = (title, publisher, isbn);
public Book(string title, string publisher)
: this(title, publisher, null) { }
public void Deconstruct(out string title, out string publisher, out string? isbn)
=> (title, publisher, isbn) = (Title, Publisher, Isbn);
public override string ToString() => Title;
var book = new Book("Professional C# 8", "Wrox Press");
// string isbn = book.Isbn; // error: converting null literal or possible null value to non-nullable type
string? isbn = book.Isbn;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment