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
// C# 6 | |
public void SomeFunStuff() | |
{ | |
Func<int, int, int> add = (x, y) => x + y; | |
int result = add(38, 4); | |
Console.WriteLine(result); | |
} | |
// C# 7 |
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
// C# 6 | |
var t1 = Tuple.Create(42, "astring"); | |
int i1 = t1.Item1; | |
string s1 = t1.Item2; | |
// C# 7 | |
var t1 = (n: 42, s: "magic"); | |
int i1 = t1.n; | |
string s1 = t1.s; |
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
// C# 7.0 | |
var t1 = (FirstName: racer.FirstName, Wins: racer.Wins); | |
int wins = t1.Wins; | |
// C# 7.1 | |
var t1 = (racer.FirstName, racer.Wins); | |
int wins = t1.Wins; |
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 n, string s) = (42, "magic"); | |
var p1 = new Person("Tom", "Turbo"); | |
(string firstName, string lastName) = p1; |
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 void PatternMatchingWithIsOperator(object o) | |
{ | |
if (o is 42) | |
{ | |
} | |
if (o is Person p) | |
{ | |
} | |
if (o is var v1) | |
{ |
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
// C# 6 | |
private readonly IBooksService _booksService; | |
public BookController(BooksService booksService) | |
{ | |
if (booksService == null) | |
{ | |
throw new ArgumentNullException(nameof(b)); | |
} | |
_booksService = booksService; |
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
// C# 7.0 | |
static void Main() | |
{ | |
SomeMethodAsync().Wait(); | |
} | |
// C# 7.1 | |
async static Task Main() | |
{ | |
await SomeMethodAsync(); |
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
// ref returns and ref locals with C# 7.0 | |
int[] _numbers = { 3, 7, 11, 15, 21 }; | |
public ref int GetNumber(int index) | |
{ | |
return ref _numbers[index]; | |
} | |
// ref readonly with C# 7.2 | |
int[] _numbers = { 3, 7, 11, 15, 21 }; | |
public ref readonly int GetNumber(int index) |
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
@{ | |
ViewData["Title"] = "Privacy Policy"; | |
} | |
<h2>@ViewData["Title"]</h2> | |
<p>Use this page to detail your site's privacy policy.</p> |
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 void ConfigureServices(IServiceCollection services) | |
{ | |
services.Configure<CookiePolicyOptions>(options => | |
{ | |
// This lambda determines whether user consent for non-essential cookies is needed for a given request. | |
options.CheckConsentNeeded = context => true; | |
options.MinimumSameSitePolicy = SameSiteMode.None; | |
}); | |
services.AddDbContext<ApplicationDbContext>(options => |