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
uint binary1 = 0b1111_0000_1010_0101_1111_0000_1010_0101; |
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 string _firstName; | |
public string FirstName | |
{ | |
get { return _firstName; } | |
set { Set(ref _firstName, value); } | |
} | |
// C# 7 | |
private string _firstName; |
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 | |
string n = "42"; | |
int result; | |
if (string.TryParse(n, out result) | |
{ | |
Console.WriteLine($"Converting to a number was successful: {result}"); | |
} | |
// C# 7 | |
string n = "42"; |
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 | |
if (Enum.TryParse(weekdayRecommendation.Entity, ignoreCase: true, | |
result: out DayOfWeek weekday)) | |
{ | |
reservation.Weekday = weekday; | |
} | |
// C# 7.2 | |
if (Enum.TryParse(weekdayRecommendation.Entity, ignoreCase: true, | |
out DayOfWeek weekday)) |
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 readonly struct Dimensions | |
{ | |
public double Length { get; } | |
public double Width { get; } | |
public Dimensions(double length, double width) | |
{ | |
Length = length; | |
Width = width; | |
} |
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 void CantChange(in AStruct s) | |
{ | |
// s can’t change | |
} |
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 | |
int x = default(int); | |
ImmutableArray<int> arr = default(ImmutableArray<int>); | |
// C# 7.1 | |
int x = default; | |
ImmutableArray<int> arr = default; |
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; |