Last active
November 21, 2021 18:25
-
-
Save georgekosmidis/22dd9b3f20165dc896f6e386dbd1a036 to your computer and use it in GitHub Desktop.
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
[Obsolete($"Call {nameof(Discard)} instead")] |
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
LambdaExpression parseExpr = (string s) => int.Parse(s); // Expression<Func<string, int>> | |
Expression parseExpr = (string s) => int.Parse(s); // Expression<Func<string, int>> |
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
<ItemGroup> | |
<Using Include="System.IO.Pipes" /> | |
</ItemGroup> |
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
<ItemGroup> | |
<Using Remove="System.Threading.Tasks" /> | |
</ItemGroup> |
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
<PropertyGroup> | |
<ImplicitUsings>enable</ImplicitUsings> | |
</PropertyGroup> |
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
global using System; | |
global using static System.Console; | |
global using Env = System.Environment; |
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
Func<string, int> parse = [SomeAttribute(1)] (s) => int.Parse(s); | |
var choose = [SomeAttribute(2)][SomeAttribute(3)] object (bool b) => b ? 1 : "two"; |
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 x2; | |
int y2; | |
(x2, y2) = (0, 1); // Works in C# 9 | |
(var x, var y) = (0, 1); // Works in C# 9 | |
(x2, var y3) = (0, 1); // Works in C# 10 onwards |
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
namespace MyCompany.MyNamespace; | |
class MyClass // Note: no indentation, no curly brackets | |
{ | |
//... | |
} |
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 parse = s => int.Parse(s); // ERROR: Not enough type info in the lambda |
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 parse = (string s) => int.Parse(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
Func<string, int> parse = (string s) => int.Parse(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
Func<int> read = Console.Read; | |
Action<string> write = Console.Write; |
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 read = Console.Read; // Just one overload; Func<int> inferred | |
var write = Console.Write; // ERROR: Multiple overloads, can't choose |
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 record struct Person(string FirstName, string LastName); |
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
object obj = new Person | |
{ | |
FirstName = "George", | |
LastName = "Kosmidis", | |
Address = new Address { City = "Munich" } | |
}; | |
if (obj is Person { Address: { City: "Munich" } }) | |
Console.WriteLine("Munich"); | |
if (obj is Person { Address.City: "Munich" }) // Extended property pattern | |
Console.WriteLine("Munich"); |
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 record struct Person | |
{ | |
public string FirstName { get; init; } | |
public string LastName { get; init; } | |
} |
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 choose = (bool b) => b ? 1 : "two"; // ERROR: Can't infer return type |
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 choose = object (bool b) => b ? 1 : "two"; // Func<bool, object> |
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
String.Create(CultureInfo.InvariantCulture, $"The result is {result}"); |
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 sb = new StringBuilder(); | |
sb.Append($"Hello {args[0]}, how are you?"); |
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 struct Address | |
{ | |
public Address() | |
{ | |
City = "<unknown>"; | |
} | |
public string City { get; init; } | |
} |
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 struct Address | |
{ | |
public string City { get; init; } = "<unknown>"; | |
} |
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 person = person with { LastName = "Kristensen" }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment