SlideShare a Scribd company logo
.NET Conf Israel 2021
What’s new in C# 10
Moaid Hathot
Senior Software Engineer @ Microsoft | ex-Azure MVP
Moaid.Hathot@outlook.com
@MoaidHathot
https://moaid.codes
https://meetup.com/Code-Digest
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
 Record structs
 Allow both assignment and declaration in the same deconstruction
 Global using directives
 File-scoped namespace declaration
 Improvements of structure types
 Interpolated string handlers
 Extended property patterns
 Improvements on lambda expressions
 Allow const interpolated strings
 Record types can seal ToString()
 Improved definite assignment
 Allow AsyncMethodBuilder attribute to methods
 CallerArgumentExpression attribute
 Enhanced #line pragma
C# 10 features
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
 Record structs
 Allow both assignment and declaration in the same deconstruction
 Global using directives
 File-scoped namespace declaration
 Improvements of structure types
 Interpolated string handlers
 Extended property patterns
 Improvements on lambda expressions
 Allow const interpolated strings
 Record types can seal ToString()
 Improved definite assignment
 Allow AsyncMethodBuilder attribute to methods
 CallerArgumentExpression attribute
 Enhanced #line pragma
C# 10 features
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
 Record structs
 Allow both assignment and declaration in the same deconstruction
 Global using directives
 File-scoped namespace declaration
 Improvements of structure types
 Interpolated string handlers
 Extended property patterns
 Improvements on lambda expressions
 Allow const interpolated strings
 Record types can seal ToString()
 Improved definite assignment
 Allow AsyncMethodBuilder attribute to methods
 CallerArgumentExpression attribute
 Enhanced #line pragma
C# 10 features
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
 Record structs
 Allow both assignment and declaration in the same deconstruction
 Global using directives
 File-scoped namespace declaration
 Improvements of structure types
 Interpolated string handlers
 Extended property patterns
 Improvements on lambda expressions
 Allow const interpolated strings
 Record types can seal ToString()
 Improved definite assignment
 Allow AsyncMethodBuilder attribute to methods
 CallerArgumentExpression attribute
 Enhanced #line pragma
C# 10 features
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
 .NET 6 SDK
 IDEs & Editors
 Visual Studio 2022
 RoslynPad
 LinqPad
 https://sharplab.io
Prerequisites
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
About Moaid Hathot
 Senior software Engineer @ Microsoft
 Ex-Azure MVP
 Software Craftsmanship advocate
 Clean Coder
 Co-Founder of Code.Digest();
 https://meetup.com/Code-Digest
Moaid Hathot
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
C# feature
Records Improvements
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
var moaid = new Person { FirstName = "Moaid", LastName = "Hathot"};
Records
public class Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public class Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
public override bool Equals(object obj)
=> obj is Person other && string.Equals(FirstName, other.FirstName) && string.Equals(LastName, other.LastName);
public override int GetHashCode()
=> HashCode.Combine(FirstName, LastName);
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public class Person : IEquatable<Person>
{
public string FirstName { get; init; }
public string LastName { get; init; }
public override bool Equals(object obj)
=> Equals(obj as Person);
public override int GetHashCode()
=> HashCode.Combine(FirstName, LastName);
public bool Equals(Person other)
=> other is { } && (FirstName, LastName) == (other.FirstName, other.LastName);
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public class Person : IEquatable<Person>
{
public string FirstName { get; init; }
public string LastName { get; init; }
public override bool Equals(object obj)
=> Equals(obj as Person);
public override int GetHashCode()
=> HashCode.Combine(FirstName, LastName);
public bool Equals(Person other)
=> other is { } && (FirstName, LastName) == (other.FirstName, other.LastName);
public override string ToString()
=> $"Person {{ FirstName: '{FirstName}', LastName: '{LastName}' }}";
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public class Person : IEquatable<Person>
{
public string FirstName { get; init; }
public string LastName { get; init; }
public override bool Equals(object obj)
=> Equals(obj as Person);
public override int GetHashCode()
=> HashCode.Combine(FirstName, LastName);
public bool Equals(Person other)
=> other is { } && (FirstName, LastName) == (other.FirstName, other.LastName);
public override string ToString()
=> $"Person {{ FirstName: '{FirstName}', LastName: '{LastName}' }}";
public static bool operator ==(Person first, Person second)
=> object.ReferenceEquals(first, second) || (first is { } && first.Equals(second));
public static bool operator !=(Person first, Person second)
=> !(first == second);
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public class Person : IEquatable<Person>
{
public string FirstName { get; init; }
public string LastName { get; init; }
public override bool Equals(object obj)
=> Equals(obj as Person);
public override int GetHashCode()
=> HashCode.Combine(FirstName, LastName);
public bool Equals(Person other)
=> other is { } && (FirstName, LastName) == (other.FirstName, other.LastName);
public override string ToString()
=> $"Person {{ FirstName: '{FirstName}', LastName: '{LastName}' }}";
public static bool operator ==(Person first, Person second)
=> object.ReferenceEquals(first, second) || (first is { } && first.Equals(second));
public static bool operator !=(Person first, Person second)
=> !(first == second);
public void Deconstruct(out string firstName, out string lastname)
=> (firstName, lastname) = (FirstName, LastName);
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
var moaid = new Person { FirstName = "Moaid", LastName = "Hathot"};
Records
public record Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
var moaid = new Person("Moaid", "Hathot");
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
var moaid = new Person("Moaid", "Hathot");
var wifu = moaid with { FirstName = "Haneeni" };
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
var moaid = new Person("Moaid", "Hathot");
var wifu = moaid with { FirstName = "Haneeni" };
var clone = moaid with { };
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
var moaid = new Person("Moaid", "Hathot");
var wifu = moaid with { FirstName = "Haneeni" };
var clone = moaid with { };
var (firstName, lastName) = moaid;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
public record struct Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
public record struct Person(string FirstName, string LastName);
public record class Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
var moaid = new Person("Moaid", "Hathot");
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid); //Person { FirstName = Moaid, LastName = Hathot }
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid);
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid); //Person { FirstName = Moaid, LastName = Hathot }
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName);
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid); //Person { FirstName = Moaid, LastName = Hathot }
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2); //Dev { FirstName = Moaid, LastName = Hathot, stack = .NET }
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName)
{
public override string ToString()
{
return $"This person name is {FirstName} {LastName}";
}
}
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName)
{
public override string ToString()
{
return $"This person name is {FirstName} {LastName}";
}
}
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid);
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName)
{
public override string ToString()
{
return $"This person name is {FirstName} {LastName}";
}
}
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid); //This person name is Moaid Hathot
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName)
{
public override string ToString()
{
return $"This person name is {FirstName} {LastName}";
}
}
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid); //This person name is Moaid Hathot
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2); //Dev { FirstName = Moaid, LastName = Hathot, stack = .NET }
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName)
{
public sealed override string ToString()
{
return $"This person name is {FirstName} {LastName}";
}
}
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid);
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName)
{
public sealed override string ToString()
{
return $"This person name is {FirstName} {LastName}";
}
}
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid); //This person name is Moaid Hathot
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Records
public record Person(string FirstName, string LastName)
{
public sealed override string ToString()
{
return $"This person name is {FirstName} {LastName}";
}
}
public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName);
var moaid = new Person("Moaid", "Hathot");
Console.WriteLine(moaid); //This person name is Moaid Hathot
var moaid2 = new Dev("Moaid", "Hathot", ".NET");
Console.WriteLine(moaid2); //This person name is Moaid Hathot
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
C# feature
Improvements of structure types
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Structs
struct Foo
{
public int Bar { get; set; }
public Foo()
{
Bar = 10;
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Structs
struct Foo
{
public int Bar { get; set; }
public Foo()
{
Bar = 10;
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Structs
struct Foo
{
public int Bar { get; set; }
public Foo()
{
Bar = 10;
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Structs
struct Foo
{
public int Bar { get; set; }
public Foo()
{
Bar = 10;
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
var foo = new Foo();
Structs
struct Foo
{
public int Bar { get; set; }
public Foo()
{
Bar = 10;
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
var foo = new Foo();
var baz = foo with { Bar = 100 };
Anonymous Types
var moaid = new { FirstName = "Moaid", LastName = "Hathot" };
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Anonymous Types
var moaid = new { FirstName = "Moaid", LastName = "Hathot" };
var wifu = moaid with { FirstName = "Haneeni" };
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
C# feature
Deconstruction Improvements
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
record Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
record Person(string FirstName, string LastName);
Person moaid = new ("Moaid", "Hathot");
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
record Person(string FirstName, string LastName);
Person moaid = new ("Moaid", "Hathot");
var (firstName, lastName) = moaid;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
public class Person(string FirstName, string LastName);
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
public class Person(string FirstName, string LastName)
{
public void Deconstruct(out string firstName, out string lastName)
{
firstName = FirstName;
lastName = LastName;
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
var (firstName, lastName) = default;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
string (foo, bar) = default;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
int (foo, bar) = default;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
int (foo, bar) = default;
(int foo, string bar) = default;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
string (firstName, lastName) = default;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
string (firstName, lastName) = default;
string firstName2;
string lastName2;
(firstName2, lastName2) = default;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
ValueTuple Deconstruction
string (firstName, lastName) = default;
string firstName2;
string lastName2;
(firstName2, lastName2) = default;
string lastName3;
(var firstName3, lastName3) = default;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
C# feature
Extended Property Patterns
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Extended property patterns
string obj = null;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Extended property patterns
string obj = null;
if (obj is { })
{
Console.WriteLine(obj);
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Extended property patterns
string obj = null;
if (obj is { Length: var length })
{
Console.WriteLine(length);
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Extended property patterns
string obj = null;
if (obj is { Length: 10 })
{
Console.WriteLine(10);
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Extended property patterns
string obj = null;
if (obj is { Length: > 3 })
{
Console.WriteLine("> 3");
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Extended property patterns
var moaid = new Person("Moaid", "Hathot");
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Extended property patterns
var moaid = new Person("Moaid", "Hathot");
if (moaid is { FirstName: { Length: > 3 } })
{
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Extended property patterns
var moaid = new Person("Moaid", "Hathot");
if (moaid is { FirstName: { Length: > 3 } })
{
}
if (moaid is { FirstName.Length: > 3 })
{
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
C# features
Improvements on Lambda expressions
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var action = () => { };
var func = () => 5;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var action = () => { };
var func = () => 5;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var action = () => { };
var func = () => 5;
Action action = () => { };
Func<int> func = () => 5;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var action = () => { };
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var action = () => { };
Action? action = () => { };
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var action = () => { };
Action? action = () => { };
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
var action2 = (string s) => { };
Lambda Improvements
var action = () => { };
Action? action = () => { };
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
var action2 = (string s) => { };
Action<string>? action2 = (string s) => { };
Lambda Improvements
var func = () => 5;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var func = () => 5;
Func<int> func = () => 5;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var func = int () => 5;
Func<int> func = int () => 5;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Lambda Improvements
var func = int () => 5;
var func = [FromBody] int () => 5;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
C# features
Constant interpolated strings
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Constant interpolated strings
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
const string Prefix = "https://";
const string Suffix = ".domain.com";
Constant interpolated strings
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
const string Prefix = "https://";
const string Suffix = ".domain.com";
const string globalSrvice = Prefix + "dotnetconf" + Suffix;
Constant interpolated strings
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
const string Prefix = "https://";
const string Suffix = ".domain.com";
const string globalSrvice = Prefix + "dotnetconf" + Suffix;
const string localService = $"{Prefix}dotnetconf-israel{Suffix}";
Constant interpolated strings
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
const string Prefix = "https://";
const string Suffix = ".domain.com";
const string globalSrvice = Prefix + "dotnetconf" + Suffix;
const string localService = $"{Prefix}dotnetconf-israel{Suffix}";
Constant interpolated strings
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
const string Prefix = "https://";
const string Suffix = ".domain.com";
const string globalSrvice = Prefix + "dotnetconf" + Suffix;
const string localService = $"{Prefix}dotnetconf-israel{Suffix}";
C# features
File-Scoped namespace
Global usings Directives
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
File-scoped namespace
using System;
namespace DotNetConf2021
{
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World!");
}
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
File-scoped namespace
namespace DotNetConf2021;
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World!");
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
File-scoped namespace
using System;
Console.WriteLine("Hello World!");
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Global using Directive
using System;
namespace DotNetConf2021
{
public class Program
{
public static void Main()
{
Console.WriteLine("Hello World!");
}
}
}
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Global using Directive
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Global using Directive
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Human = DotNetConf2021.Person;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Global using Directive
global using System;
global using System.Linq;
global using System.Collections.Generic;
global using System.Threading;
global using System.Threading.Tasks;
global using Human = DotNetConf2021.Person;
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
Best of //Build 2021
Questions?
Moaid Hathot
Senior Software Engineer @ Microsoft | ex-Azure MVP
Moaid.Hathot@outlook.com
@MoaidHathot
https://moaid.codes
https://meetup.com/Code-Digest
Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10

More Related Content

PPTX
Understanding gRPC Authentication Methods
PDF
TDC2016POA | Trilha JavaScript - JavaScript Promises na PrĂĄtica
PPTX
Build your own Blockchain with the right tool for your application
PDF
Usable APIs at Scale
PPTX
Dependency Injections in Kotlin
 
PPTX
Best of build 2021 - C# 10 & .NET 6
PPTX
New C# features
PPTX
C# Today and Tomorrow
Understanding gRPC Authentication Methods
TDC2016POA | Trilha JavaScript - JavaScript Promises na PrĂĄtica
Build your own Blockchain with the right tool for your application
Usable APIs at Scale
Dependency Injections in Kotlin
 
Best of build 2021 - C# 10 & .NET 6
New C# features
C# Today and Tomorrow

Similar to What's new in c# 10 (20)

PPTX
What's new in C# 11
PDF
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
PPTX
Linq Introduction
PDF
C# 7.x What's new and what's coming with C# 8
PPTX
C# 6 and 7 and Futures 20180607
PPSX
What's new in C# 6 - NetPonto Porto 20160116
PPSX
Tuga it 2016 - What's New In C# 6
PPTX
What’s new in .NET
PPSX
What's New In C# 7
PPTX
Whats New In C Sharp 4 And Vb 10
PPTX
Novidades do c# 7 e 8
PDF
C# - What's next
PDF
C# - What's Next?
PPTX
5. c sharp language overview part ii
PPTX
.Net Framework 2 fundamentals
PPTX
Tamir Dresher - DotNet 7 What's new.pptx
PPTX
C# overview part 2
PPTX
C# 8 and Beyond
PPTX
What's new in c#7
PPTX
What's new in C# 6.0
What's new in C# 11
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
Linq Introduction
C# 7.x What's new and what's coming with C# 8
C# 6 and 7 and Futures 20180607
What's new in C# 6 - NetPonto Porto 20160116
Tuga it 2016 - What's New In C# 6
What’s new in .NET
What's New In C# 7
Whats New In C Sharp 4 And Vb 10
Novidades do c# 7 e 8
C# - What's next
C# - What's Next?
5. c sharp language overview part ii
.Net Framework 2 fundamentals
Tamir Dresher - DotNet 7 What's new.pptx
C# overview part 2
C# 8 and Beyond
What's new in c#7
What's new in C# 6.0
Ad

More from Moaid Hathot (20)

PPTX
Demystifying C#'s Interpolated string Handlers
PPTX
Azure Bicep for Developers
PPTX
Demystifying C#'s Interpolated string Handlers
PPTX
ChatGPT and Beyond Using AI Tools to Enhance Academic Researc
PPTX
Dapr- Distributed Application Runtime
PPTX
What's coming in C# 11
PPTX
Introduction to .NET MAUI
PDF
Developer cloud roadmap keynote
PPTX
What's new in c# 10
PPTX
Intro to Azure Static Web Apps
PPTX
About me - Atidna
PPTX
About me - Rothschild Partnerships
PPTX
What's coming in c# 9.0
PPTX
What's Coming in C# 9.0
PPTX
Introduction to azure
PPTX
Distributed Application Runtime (Dapr) - Azure Israel 2020
PPTX
Dapr: distributed application runtime
PPTX
Dapr: the glue to your microservices
PPTX
A serverless IoT Story From Design to Production and Monitoring
PPTX
What's new in c# 8.0
Demystifying C#'s Interpolated string Handlers
Azure Bicep for Developers
Demystifying C#'s Interpolated string Handlers
ChatGPT and Beyond Using AI Tools to Enhance Academic Researc
Dapr- Distributed Application Runtime
What's coming in C# 11
Introduction to .NET MAUI
Developer cloud roadmap keynote
What's new in c# 10
Intro to Azure Static Web Apps
About me - Atidna
About me - Rothschild Partnerships
What's coming in c# 9.0
What's Coming in C# 9.0
Introduction to azure
Distributed Application Runtime (Dapr) - Azure Israel 2020
Dapr: distributed application runtime
Dapr: the glue to your microservices
A serverless IoT Story From Design to Production and Monitoring
What's new in c# 8.0
Ad

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Digital Strategies for Manufacturing Companies
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
medical staffing services at VALiNTRY
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPT
Introduction Database Management System for Course Database
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
history of c programming in notes for students .pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
Upgrade and Innovation Strategies for SAP ERP Customers
How to Migrate SBCGlobal Email to Yahoo Easily
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms I-SECS-1021-03
Digital Strategies for Manufacturing Companies
Softaken Excel to vCard Converter Software.pdf
How Creative Agencies Leverage Project Management Software.pdf
medical staffing services at VALiNTRY
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Introduction Database Management System for Course Database
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
CHAPTER 2 - PM Management and IT Context
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
history of c programming in notes for students .pptx
Wondershare Filmora 15 Crack With Activation Key [2025
L1 - Introduction to python Backend.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 

What's new in c# 10

  • 1. .NET Conf Israel 2021 What’s new in C# 10 Moaid Hathot Senior Software Engineer @ Microsoft | ex-Azure MVP Moaid.Hathot@outlook.com @MoaidHathot https://moaid.codes https://meetup.com/Code-Digest Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 2.  Record structs  Allow both assignment and declaration in the same deconstruction  Global using directives  File-scoped namespace declaration  Improvements of structure types  Interpolated string handlers  Extended property patterns  Improvements on lambda expressions  Allow const interpolated strings  Record types can seal ToString()  Improved definite assignment  Allow AsyncMethodBuilder attribute to methods  CallerArgumentExpression attribute  Enhanced #line pragma C# 10 features Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 3.  Record structs  Allow both assignment and declaration in the same deconstruction  Global using directives  File-scoped namespace declaration  Improvements of structure types  Interpolated string handlers  Extended property patterns  Improvements on lambda expressions  Allow const interpolated strings  Record types can seal ToString()  Improved definite assignment  Allow AsyncMethodBuilder attribute to methods  CallerArgumentExpression attribute  Enhanced #line pragma C# 10 features Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 4.  Record structs  Allow both assignment and declaration in the same deconstruction  Global using directives  File-scoped namespace declaration  Improvements of structure types  Interpolated string handlers  Extended property patterns  Improvements on lambda expressions  Allow const interpolated strings  Record types can seal ToString()  Improved definite assignment  Allow AsyncMethodBuilder attribute to methods  CallerArgumentExpression attribute  Enhanced #line pragma C# 10 features Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 5.  Record structs  Allow both assignment and declaration in the same deconstruction  Global using directives  File-scoped namespace declaration  Improvements of structure types  Interpolated string handlers  Extended property patterns  Improvements on lambda expressions  Allow const interpolated strings  Record types can seal ToString()  Improved definite assignment  Allow AsyncMethodBuilder attribute to methods  CallerArgumentExpression attribute  Enhanced #line pragma C# 10 features Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 6.  .NET 6 SDK  IDEs & Editors  Visual Studio 2022  RoslynPad  LinqPad  https://sharplab.io Prerequisites Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 7. About Moaid Hathot  Senior software Engineer @ Microsoft  Ex-Azure MVP  Software Craftsmanship advocate  Clean Coder  Co-Founder of Code.Digest();  https://meetup.com/Code-Digest Moaid Hathot Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 8. C# feature Records Improvements Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 9. Records public record Person { public string FirstName { get; init; } public string LastName { get; init; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 10. Records public record Person { public string FirstName { get; init; } public string LastName { get; init; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 var moaid = new Person { FirstName = "Moaid", LastName = "Hathot"};
  • 11. Records public class Person { public string FirstName { get; init; } public string LastName { get; init; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 12. Records public class Person { public string FirstName { get; init; } public string LastName { get; init; } public override bool Equals(object obj) => obj is Person other && string.Equals(FirstName, other.FirstName) && string.Equals(LastName, other.LastName); public override int GetHashCode() => HashCode.Combine(FirstName, LastName); } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 13. Records public class Person : IEquatable<Person> { public string FirstName { get; init; } public string LastName { get; init; } public override bool Equals(object obj) => Equals(obj as Person); public override int GetHashCode() => HashCode.Combine(FirstName, LastName); public bool Equals(Person other) => other is { } && (FirstName, LastName) == (other.FirstName, other.LastName); } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 14. Records public class Person : IEquatable<Person> { public string FirstName { get; init; } public string LastName { get; init; } public override bool Equals(object obj) => Equals(obj as Person); public override int GetHashCode() => HashCode.Combine(FirstName, LastName); public bool Equals(Person other) => other is { } && (FirstName, LastName) == (other.FirstName, other.LastName); public override string ToString() => $"Person {{ FirstName: '{FirstName}', LastName: '{LastName}' }}"; } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 15. Records public class Person : IEquatable<Person> { public string FirstName { get; init; } public string LastName { get; init; } public override bool Equals(object obj) => Equals(obj as Person); public override int GetHashCode() => HashCode.Combine(FirstName, LastName); public bool Equals(Person other) => other is { } && (FirstName, LastName) == (other.FirstName, other.LastName); public override string ToString() => $"Person {{ FirstName: '{FirstName}', LastName: '{LastName}' }}"; public static bool operator ==(Person first, Person second) => object.ReferenceEquals(first, second) || (first is { } && first.Equals(second)); public static bool operator !=(Person first, Person second) => !(first == second); } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 16. Records public class Person : IEquatable<Person> { public string FirstName { get; init; } public string LastName { get; init; } public override bool Equals(object obj) => Equals(obj as Person); public override int GetHashCode() => HashCode.Combine(FirstName, LastName); public bool Equals(Person other) => other is { } && (FirstName, LastName) == (other.FirstName, other.LastName); public override string ToString() => $"Person {{ FirstName: '{FirstName}', LastName: '{LastName}' }}"; public static bool operator ==(Person first, Person second) => object.ReferenceEquals(first, second) || (first is { } && first.Equals(second)); public static bool operator !=(Person first, Person second) => !(first == second); public void Deconstruct(out string firstName, out string lastname) => (firstName, lastname) = (FirstName, LastName); } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 17. Records public record Person { public string FirstName { get; init; } public string LastName { get; init; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 18. Records public record Person { public string FirstName { get; init; } public string LastName { get; init; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 var moaid = new Person { FirstName = "Moaid", LastName = "Hathot"};
  • 19. Records public record Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 20. Records public record Person(string FirstName, string LastName); var moaid = new Person("Moaid", "Hathot"); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 21. Records public record Person(string FirstName, string LastName); var moaid = new Person("Moaid", "Hathot"); var wifu = moaid with { FirstName = "Haneeni" }; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 22. Records public record Person(string FirstName, string LastName); var moaid = new Person("Moaid", "Hathot"); var wifu = moaid with { FirstName = "Haneeni" }; var clone = moaid with { }; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 23. Records public record Person(string FirstName, string LastName); var moaid = new Person("Moaid", "Hathot"); var wifu = moaid with { FirstName = "Haneeni" }; var clone = moaid with { }; var (firstName, lastName) = moaid; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 24. Records public record Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 25. Records public record Person(string FirstName, string LastName); public record struct Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 26. Records public record Person(string FirstName, string LastName); public record struct Person(string FirstName, string LastName); public record class Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 27. Records public record Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 28. Records public record Person(string FirstName, string LastName); var moaid = new Person("Moaid", "Hathot"); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 29. Records public record Person(string FirstName, string LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 30. Records public record Person(string FirstName, string LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); //Person { FirstName = Moaid, LastName = Hathot } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 31. Records public record Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 32. Records public record Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 33. Records public record Person(string FirstName, string LastName); public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 34. Records public record Person(string FirstName, string LastName); public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 35. Records public record Person(string FirstName, string LastName); public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); //Person { FirstName = Moaid, LastName = Hathot } var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 36. Records public record Person(string FirstName, string LastName); public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); //Person { FirstName = Moaid, LastName = Hathot } var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); //Dev { FirstName = Moaid, LastName = Hathot, stack = .NET } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 37. Records public record Person(string FirstName, string LastName) { public override string ToString() { return $"This person name is {FirstName} {LastName}"; } } public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 38. Records public record Person(string FirstName, string LastName) { public override string ToString() { return $"This person name is {FirstName} {LastName}"; } } public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 39. Records public record Person(string FirstName, string LastName) { public override string ToString() { return $"This person name is {FirstName} {LastName}"; } } public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); //This person name is Moaid Hathot var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 40. Records public record Person(string FirstName, string LastName) { public override string ToString() { return $"This person name is {FirstName} {LastName}"; } } public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); //This person name is Moaid Hathot var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); //Dev { FirstName = Moaid, LastName = Hathot, stack = .NET } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 41. Records public record Person(string FirstName, string LastName) { public sealed override string ToString() { return $"This person name is {FirstName} {LastName}"; } } public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 42. Records public record Person(string FirstName, string LastName) { public sealed override string ToString() { return $"This person name is {FirstName} {LastName}"; } } public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); //This person name is Moaid Hathot var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 43. Records public record Person(string FirstName, string LastName) { public sealed override string ToString() { return $"This person name is {FirstName} {LastName}"; } } public record Dev(string FirstName, string LastName, string stack) : Person(FirstName, LastName); var moaid = new Person("Moaid", "Hathot"); Console.WriteLine(moaid); //This person name is Moaid Hathot var moaid2 = new Dev("Moaid", "Hathot", ".NET"); Console.WriteLine(moaid2); //This person name is Moaid Hathot Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 44. C# feature Improvements of structure types Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 45. Structs struct Foo { public int Bar { get; set; } public Foo() { Bar = 10; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 46. Structs struct Foo { public int Bar { get; set; } public Foo() { Bar = 10; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 47. Structs struct Foo { public int Bar { get; set; } public Foo() { Bar = 10; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 48. Structs struct Foo { public int Bar { get; set; } public Foo() { Bar = 10; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 var foo = new Foo();
  • 49. Structs struct Foo { public int Bar { get; set; } public Foo() { Bar = 10; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 var foo = new Foo(); var baz = foo with { Bar = 100 };
  • 50. Anonymous Types var moaid = new { FirstName = "Moaid", LastName = "Hathot" }; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 51. Anonymous Types var moaid = new { FirstName = "Moaid", LastName = "Hathot" }; var wifu = moaid with { FirstName = "Haneeni" }; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 52. C# feature Deconstruction Improvements Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 53. ValueTuple Deconstruction record Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 54. ValueTuple Deconstruction record Person(string FirstName, string LastName); Person moaid = new ("Moaid", "Hathot"); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 55. ValueTuple Deconstruction record Person(string FirstName, string LastName); Person moaid = new ("Moaid", "Hathot"); var (firstName, lastName) = moaid; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 56. ValueTuple Deconstruction public class Person(string FirstName, string LastName); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 57. ValueTuple Deconstruction public class Person(string FirstName, string LastName) { public void Deconstruct(out string firstName, out string lastName) { firstName = FirstName; lastName = LastName; } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 58. ValueTuple Deconstruction var (firstName, lastName) = default; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 59. ValueTuple Deconstruction string (foo, bar) = default; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 60. ValueTuple Deconstruction int (foo, bar) = default; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 61. ValueTuple Deconstruction int (foo, bar) = default; (int foo, string bar) = default; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 62. ValueTuple Deconstruction string (firstName, lastName) = default; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 63. ValueTuple Deconstruction string (firstName, lastName) = default; string firstName2; string lastName2; (firstName2, lastName2) = default; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 64. ValueTuple Deconstruction string (firstName, lastName) = default; string firstName2; string lastName2; (firstName2, lastName2) = default; string lastName3; (var firstName3, lastName3) = default; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 65. C# feature Extended Property Patterns Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 66. Extended property patterns string obj = null; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 67. Extended property patterns string obj = null; if (obj is { }) { Console.WriteLine(obj); } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 68. Extended property patterns string obj = null; if (obj is { Length: var length }) { Console.WriteLine(length); } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 69. Extended property patterns string obj = null; if (obj is { Length: 10 }) { Console.WriteLine(10); } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 70. Extended property patterns string obj = null; if (obj is { Length: > 3 }) { Console.WriteLine("> 3"); } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 71. Extended property patterns var moaid = new Person("Moaid", "Hathot"); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 72. Extended property patterns var moaid = new Person("Moaid", "Hathot"); if (moaid is { FirstName: { Length: > 3 } }) { } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 73. Extended property patterns var moaid = new Person("Moaid", "Hathot"); if (moaid is { FirstName: { Length: > 3 } }) { } if (moaid is { FirstName.Length: > 3 }) { } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 74. C# features Improvements on Lambda expressions Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 75. Lambda Improvements var action = () => { }; var func = () => 5; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 76. Lambda Improvements var action = () => { }; var func = () => 5; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 77. Lambda Improvements var action = () => { }; var func = () => 5; Action action = () => { }; Func<int> func = () => 5; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 78. Lambda Improvements var action = () => { }; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 79. Lambda Improvements var action = () => { }; Action? action = () => { }; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 80. Lambda Improvements var action = () => { }; Action? action = () => { }; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 var action2 = (string s) => { };
  • 81. Lambda Improvements var action = () => { }; Action? action = () => { }; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 var action2 = (string s) => { }; Action<string>? action2 = (string s) => { };
  • 82. Lambda Improvements var func = () => 5; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 83. Lambda Improvements var func = () => 5; Func<int> func = () => 5; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 84. Lambda Improvements var func = int () => 5; Func<int> func = int () => 5; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 85. Lambda Improvements var func = int () => 5; var func = [FromBody] int () => 5; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 86. C# features Constant interpolated strings Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 87. Constant interpolated strings Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 const string Prefix = "https://"; const string Suffix = ".domain.com";
  • 88. Constant interpolated strings Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 const string Prefix = "https://"; const string Suffix = ".domain.com"; const string globalSrvice = Prefix + "dotnetconf" + Suffix;
  • 89. Constant interpolated strings Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 const string Prefix = "https://"; const string Suffix = ".domain.com"; const string globalSrvice = Prefix + "dotnetconf" + Suffix; const string localService = $"{Prefix}dotnetconf-israel{Suffix}";
  • 90. Constant interpolated strings Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 const string Prefix = "https://"; const string Suffix = ".domain.com"; const string globalSrvice = Prefix + "dotnetconf" + Suffix; const string localService = $"{Prefix}dotnetconf-israel{Suffix}";
  • 91. Constant interpolated strings Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10 const string Prefix = "https://"; const string Suffix = ".domain.com"; const string globalSrvice = Prefix + "dotnetconf" + Suffix; const string localService = $"{Prefix}dotnetconf-israel{Suffix}";
  • 92. C# features File-Scoped namespace Global usings Directives Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 93. File-scoped namespace using System; namespace DotNetConf2021 { public class Program { public static void Main() { Console.WriteLine("Hello World!"); } } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 94. File-scoped namespace namespace DotNetConf2021; using System; public class Program { public static void Main() { Console.WriteLine("Hello World!"); } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 95. File-scoped namespace using System; Console.WriteLine("Hello World!"); Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 96. Global using Directive using System; namespace DotNetConf2021 { public class Program { public static void Main() { Console.WriteLine("Hello World!"); } } } Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 97. Global using Directive using System; using System.Linq; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 98. Global using Directive using System; using System.Linq; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Human = DotNetConf2021.Person; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 99. Global using Directive global using System; global using System.Linq; global using System.Collections.Generic; global using System.Threading; global using System.Threading.Tasks; global using Human = DotNetConf2021.Person; Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10
  • 100. Best of //Build 2021 Questions? Moaid Hathot Senior Software Engineer @ Microsoft | ex-Azure MVP Moaid.Hathot@outlook.com @MoaidHathot https://moaid.codes https://meetup.com/Code-Digest Code.Digest | .NET Conf Israel 2021 | What’s new In C# 10