Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Last active June 14, 2018 06:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save christiannagel/dedf92ef4675224c94159b18855cef58 to your computer and use it in GitHub Desktop.
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