C# 8 Book Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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