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
static string GetIsbn1(Book book) | |
{ | |
string? isbn = book.Isbn; | |
if (isbn == null) | |
{ | |
return string.Empty; | |
} | |
return isbn; | |
} |
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 SomeClass : ILegacyInterface | |
{ | |
public string? Foo() => null; | |
} | |
class AnotherClass : ILegacyInterface | |
{ | |
public string Foo() => "a string"; | |
} |
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 newglory = new NewAndGlory(); | |
string? s1 = newglory.GetANullString(); | |
string s2 = newglory.GetAString(); | |
// string s3 = newglory.PassAString(null); // error: cannot convert null literal to non-nullable reference or unconstrained type parameter | |
var old = new Legacy(); | |
string s4 = old.GetANullString(); // no error, s1 is null! | |
string s5 = old.PassAString(null); // no error |
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) { } |
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
public class Legacy | |
{ | |
public string GetANullString() => null; | |
public string PassAString(string s) | |
{ | |
if (s == null) throw new ArgumentNullException(nameof(s)); | |
return s.ToUpper(); | |
} | |
} |
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
{ | |
"version": "1.0", | |
"defaultProvider": "cdnjs", | |
"libraries": [ | |
{ | |
"library": "jquery@3.3.1", | |
"destination": "wwwroot/lib/jQuery", | |
"files": ["jquery.js", "jquery.min.js", "jquery.min.map"] | |
} | |
] |
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
{ | |
"version": "1.0", | |
"defaultProvider": "cdnjs", | |
"libraries": [] | |
} |
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
public class NewAndGlory | |
{ | |
public string? GetANullString() => null; | |
public string GetAString() => "a string"; | |
public string PassAString(string s) => s.ToUpper(); | |
} |
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
int i1 = 4; // null is not allowed | |
int? i2 = null; // null is allowed | |
string s1 = "a string"; // null is not allowed | |
string? s2 = null; // a nullable string |
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
private ServiceProvider ConfigureServices() | |
{ | |
var services = new ServiceCollection(); | |
services.AddLogging(builder => | |
{ | |
builder.AddFilter((category, level) => true); | |
builder.AddConsole(options => options.IncludeScopes = true); | |
}); | |
services.AddHttpClient("cni", client => | |
{ |