SlideShare a Scribd company logo
1 of 29
C# 8.0 new features
Who Am I?
Miguel has over 10 years of experience with
Microsoft Technologies. Specialized with many
things in the Microsoft ecosystem, including C#,
F#, and Azure, he likes to blog about his
engineering notes and technology in general. He
is also very involved in the Montréal msdevmtl
community where he is a co-organizer.
NEXUS INNOVATIONS - PRÉSENTATION 2
https://blog.miguelbernard.com
https://www.linkedin.com/in/miguelbernard/
@MiguelBernard88
https://github.com/mbernard
New features
• Readonly members
• Default interface methods
• Pattern matching enhancements
• Using declarations
• Static local functions
• Disposable ref structs
• Nullable reference types
• Asynchronous streams
• Indices and ranges
• Null-coalescing assignment
• Unmanaged constructed types
• Stackalloc in nested expressions
• Enhancement of interpolated verbatim strings
NEXUS INNOVATIONS - PRÉSENTATION 3
Nullable reference types
To enable it
• In .csproj
• <LangVersion>8.0</LangVersion>
• <Nullable>Enable</Nullable>
• In code
• #nullable enable
• #nullable restore
NEXUS INNOVATIONS - PRÉSENTATION 4
Nullable reference types
? nullable operator
! Null forgiving operator
i.e.
NEXUS INNOVATIONS - PRÉSENTATION 5
string? a = null;
a!.Length;
Nullable reference types
DEMO
NEXUS INNOVATIONS - PRÉSENTATION 6
Pattern matching enhancements
Use case of a Toll service
V1 -Price per vehicle type
• 🚗Car -> 2$
• 🚕Taxi -> 3.50$
• 🚌Bus -> 5$
• 🚚Truck -> 10$
NEXUS INNOVATIONS - PRÉSENTATION 7
Pattern matching enhancements
V2 - Price considering occupancy
• Car and taxi
• No passengers -> +0.50 $
• 2 passengers -> -0.50 $
• 3 or more passengers -> -1$
NEXUS INNOVATIONS - PRÉSENTATION 8
Pattern matching enhancements
V3 - Price considering occupancy
• Car and taxi
• No passengers -> +0.50 $
• 2 passengers -> -0.50 $
• 3 or more passengers -> -1$
• Bus
• Less than 50% full -> +2$
• More than 90% full -> -1$
NEXUS INNOVATIONS - PRÉSENTATION 9
Pattern matching enhancements
V4 - Price considering weight
• > 5000 lbs -> +5$
• < 3000 lbs -> -2$
NEXUS INNOVATIONS - PRÉSENTATION 10
Pattern matching enhancements
V5 – Refactor Car and Taxi!
NEXUS INNOVATIONS - PRÉSENTATION 11
Asynchronous streams
To have an async stream you need 3 properties
• It’s declared with the ‘async’ modifier
• It returns an IAsyncEnumerable<T>
• The method contains ‘yield return’ statements
NEXUS INNOVATIONS - PRÉSENTATION 12
Asynchronous streams
NEXUS INNOVATIONS - PRÉSENTATION 13
internal async IAsyncEnumerable<int> GenerateSequence()
{
for (int i = 0; i < 20; i++)
{
// every 3 elements, wait 2 seconds:
if (i % 3 == 0)
await Task.Delay(3000);
yield return i;
}
}
internal async Task<int> ConsumeStream()
{
await foreach (var number in GenerateSequence())
{
Console.WriteLine($"The time is {DateTime.Now:hh:mm:ss}. Retrieved {number}");
}
return 0;
}
Indices and ranges
New operators
• The index from end operator ^, which specifies that an index is relative to the
end of the sequence
• The range operator .., which specifies the start and end of a range as its
operands
NEXUS INNOVATIONS - PRÉSENTATION 14
Indices and ranges
Notes
• The ^0 index is the same as sequence[sequence.Length].
• Note that sequence[^0] does throw an exception, just as
sequence[sequence.Length] does
• For any number n, the index ^n is the same as sequence.Length – n
• The range [0..^0] represents the entire range, just as [0..sequence.Length]
represents the entire range.
NEXUS INNOVATIONS - PRÉSENTATION 15
Indices and ranges
NEXUS INNOVATIONS - PRÉSENTATION 16
private string[] words = new string[]
{
// index from start index from end
"The", // 0 ^9
"quick", // 1 ^8
"brown", // 2 ^7
"fox", // 3 ^6
"jumped", // 4 ^5
"over", // 5 ^4
"the", // 6 ^3
"lazy", // 7 ^2
"dog" // 8 ^1
};
Indices and ranges
NEXUS INNOVATIONS - PRÉSENTATION 17
var allWords = words[..]; // contains "The" through "dog".
var firstPhrase = words[..4]; // contains "The" through "fox"
var lastPhrase = words[6..]; // contains "the, "lazy" and "dog"
var lazyDog = words[^2..^0];
Index the = ^3;
words[the];
Range phrase = 1..4;
words[phrase];
Default interface methods
Demo!
NEXUS INNOVATIONS - PRÉSENTATION 18
Static local functions
NEXUS INNOVATIONS - PRÉSENTATION 19
int M()
{
int y = 5;
int x = 7;
return Add(x, y);
static int Add(int left, int right) => left + right;
}
You can now add the static modifier to local functions to ensure that local function doesn't capture (reference) any
variables from the enclosing scope.
Doing so generates CS8421, "A static local function can't contain a reference to <variable>."
Null-coalescing assignment
C# 8.0 introduces the null-coalescing assignment operator ??=. You can use
the ??= operator to assign the value of its right-hand operand to its left-hand
operand only if the left-hand operand evaluates to null.
NEXUS INNOVATIONS - PRÉSENTATION 20
List<int> numbers = null;
int? a = null;
(numbers ??= new List<int>()).Add(5);
Console.WriteLine(string.Join(" ", numbers)); // output: 5
numbers.Add(a ??= 0);
Console.WriteLine(string.Join(" ", numbers)); // output: 5 0
Console.WriteLine(a); // output: 0
Using declarations
Using variables are automatically disposed at the end of the current scope
NEXUS INNOVATIONS - PRÉSENTATION 21
public void Method()
{
using var file = new StreamWriter(“myFile.txt”);
…logic here…
} // Disposed here
public void Method()
{
using(var file = new StreamWriter(“myFile.txt”))
{
…logic here…
} // Disposed here
}
Enhancement of interpolated verbatim strings
Order of the $ and @ tokens in interpolated verbatim strings can be any: both
$@"..." and @$"..." are valid interpolated verbatim strings
In earlier C# versions, the $ token must appear before the @ token
NEXUS INNOVATIONS - PRÉSENTATION 22
Readonly members
• Only applicable for struct
• Advantages
• The compilier can now enforce your
intent
• Doing so will enable to compiler to
perform performance optimizations on
your code
NEXUS INNOVATIONS - PRÉSENTATION 23
public struct Point
{
public double X { get; set; }
public double Y { get; set; }
public readonly double Distance =>
Math.Sqrt(X * X + Y * Y);
public readonly override string ToString() =>
$"({X}, {Y}) is {Distance} from the origin";
}
Unmanaged constructed types
NEXUS INNOVATIONS - PRÉSENTATION 24
public struct Coords<T> where T : unmanaged
{
public T X;
public T Y;
}
Span<Coords<int>> coordinates = stackalloc[]
{
new Coords<int> { X = 0, Y = 0 },
new Coords<int> { X = 0, Y = 3 },
new Coords<int> { X = 4, Y = 0 }
};
Stackalloc in nested expressions
Starting with C# 8.0, if the result of a stackalloc expression is of the Span<T>
or ReadOnlySpan<T> type, you can use the stackalloc expression in other
expressions
NEXUS INNOVATIONS - PRÉSENTATION 25
Span<int> numbers = stackalloc[] { 1, 2, 3, 4, 5, 6 };
var ind = numbers.IndexOfAny(stackalloc[] { 2, 4, 6 ,8 });
Console.WriteLine(ind); // output: 1
Disposable ref structs
A struct declared with the ref modifier may not implement any interfaces and so
can't implement IDisposable.
Therefore, to enable a ref struct to be disposed, it must have an accessible
`void Dispose()` method. This feature also applies to readonly ref struct
declarations.
NEXUS INNOVATIONS - PRÉSENTATION 26
ref struct Book
{
public void Dispose()
{
}
}
References
• https://github.com/mbernard/csharp8sample
• https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8
• https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/default-interface-
methods-versions
NEXUS INNOVATIONS - PRÉSENTATION 27
Questions?
Questions?
NEXUS INNOVATIONS - PRÉSENTATION 28
https://blog.miguelbernard.com
https://www.linkedin.com/in/miguelbernard/
@MiguelBernard88
https://github.com/mbernard
1751 Richardson, suite, 4.500
H3K 1G6, Montréa, Canada
NEXUS INNOVATIONS - PRÉSENTATION 29

More Related Content

What's hot

C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloadingmohamed sikander
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScriptGarth Gilmour
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6FITC
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScripttmont
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioLuis Atencio
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeCory Forsyth
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphismmohamed sikander
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekyoavrubin
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notesRajiv Gupta
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++vidyamittal
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in PythonColin Su
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
Oops practical file
Oops practical fileOops practical file
Oops practical fileAnkit Dixit
 

What's hot (20)

C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis Atencio
 
Container adapters
Container adaptersContainer adapters
Container adapters
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphism
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks week
 
Advance C++notes
Advance C++notesAdvance C++notes
Advance C++notes
 
Advance features of C++
Advance features of C++Advance features of C++
Advance features of C++
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in Python
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
C# 7
C# 7C# 7
C# 7
 
Oops practical file
Oops practical fileOops practical file
Oops practical file
 

Similar to C sharp 8.0 new features

The Present and Future of the Web Platform
The Present and Future of the Web PlatformThe Present and Future of the Web Platform
The Present and Future of the Web PlatformC4Media
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverMongoDB
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)jeffz
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)Christian Nagel
 
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor ExtensionsConnect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensionsstable|kernel
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NETDoommaker
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Windows Developer
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCAndy Butland
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 developmentFisnik Doko
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8Christian Nagel
 
Task and Data Parallelism: Real-World Examples
Task and Data Parallelism: Real-World ExamplesTask and Data Parallelism: Real-World Examples
Task and Data Parallelism: Real-World ExamplesSasha Goldshtein
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Insidejeffz
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkBob German
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8tdc-globalcode
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to ElixirDiacode
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonAlex Payne
 

Similar to C sharp 8.0 new features (20)

The Present and Future of the Web Platform
The Present and Future of the Web PlatformThe Present and Future of the Web Platform
The Present and Future of the Web Platform
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node Driver
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)The Evolution of Async-Programming on .NET Platform (.Net China, C#)
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor ExtensionsConnect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 development
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
 
Task and Data Parallelism: Real-World Examples
Task and Data Parallelism: Real-World ExamplesTask and Data Parallelism: Real-World Examples
Task and Data Parallelism: Real-World Examples
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
LINQ Inside
LINQ InsideLINQ Inside
LINQ Inside
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint Framework
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 

More from MSDEVMTL

Intro grpc.net
Intro  grpc.netIntro  grpc.net
Intro grpc.netMSDEVMTL
 
Grpc and asp.net partie 2
Grpc and asp.net partie 2Grpc and asp.net partie 2
Grpc and asp.net partie 2MSDEVMTL
 
Property based testing
Property based testingProperty based testing
Property based testingMSDEVMTL
 
Improve cloud visibility and cost in Microsoft Azure
Improve cloud visibility and cost in Microsoft AzureImprove cloud visibility and cost in Microsoft Azure
Improve cloud visibility and cost in Microsoft AzureMSDEVMTL
 
Return on Ignite 2019: Azure, .NET, A.I. & Data
Return on Ignite 2019: Azure, .NET, A.I. & DataReturn on Ignite 2019: Azure, .NET, A.I. & Data
Return on Ignite 2019: Azure, .NET, A.I. & DataMSDEVMTL
 
Asp.net core 3
Asp.net core 3Asp.net core 3
Asp.net core 3MSDEVMTL
 
MSDEVMTL Informations 2019
MSDEVMTL Informations 2019MSDEVMTL Informations 2019
MSDEVMTL Informations 2019MSDEVMTL
 
Common features in webapi aspnetcore
Common features in webapi aspnetcoreCommon features in webapi aspnetcore
Common features in webapi aspnetcoreMSDEVMTL
 
Groupe Excel et Power BI - Rencontre du 25 septembre 2018
Groupe Excel et Power BI  - Rencontre du 25 septembre 2018Groupe Excel et Power BI  - Rencontre du 25 septembre 2018
Groupe Excel et Power BI - Rencontre du 25 septembre 2018MSDEVMTL
 
Api gateway
Api gatewayApi gateway
Api gatewayMSDEVMTL
 
Common features in webapi aspnetcore
Common features in webapi aspnetcoreCommon features in webapi aspnetcore
Common features in webapi aspnetcoreMSDEVMTL
 
Stephane Lapointe: Governance in Azure, keep control of your environments
Stephane Lapointe: Governance in Azure, keep control of your environmentsStephane Lapointe: Governance in Azure, keep control of your environments
Stephane Lapointe: Governance in Azure, keep control of your environmentsMSDEVMTL
 
Eric Routhier: Garder le contrôle sur vos coûts Azure
Eric Routhier: Garder le contrôle sur vos coûts AzureEric Routhier: Garder le contrôle sur vos coûts Azure
Eric Routhier: Garder le contrôle sur vos coûts AzureMSDEVMTL
 
Data science presentation
Data science presentationData science presentation
Data science presentationMSDEVMTL
 
Michel Ouellette + Gabriel Lainesse: Process Automation & Data Analytics at S...
Michel Ouellette + Gabriel Lainesse: Process Automation & Data Analytics at S...Michel Ouellette + Gabriel Lainesse: Process Automation & Data Analytics at S...
Michel Ouellette + Gabriel Lainesse: Process Automation & Data Analytics at S...MSDEVMTL
 
Open id connect, azure ad, angular 5, web api core
Open id connect, azure ad, angular 5, web api coreOpen id connect, azure ad, angular 5, web api core
Open id connect, azure ad, angular 5, web api coreMSDEVMTL
 
Yoann Clombe : Fail fast, iterate quickly with power bi and google analytics
Yoann Clombe : Fail fast, iterate quickly with power bi and google analyticsYoann Clombe : Fail fast, iterate quickly with power bi and google analytics
Yoann Clombe : Fail fast, iterate quickly with power bi and google analyticsMSDEVMTL
 
CAE: etude de cas - Rolling Average
CAE: etude de cas - Rolling AverageCAE: etude de cas - Rolling Average
CAE: etude de cas - Rolling AverageMSDEVMTL
 
CAE: etude de cas
CAE: etude de casCAE: etude de cas
CAE: etude de casMSDEVMTL
 
Dan Edwards : Data visualization best practices with Power BI
Dan Edwards : Data visualization best practices with Power BIDan Edwards : Data visualization best practices with Power BI
Dan Edwards : Data visualization best practices with Power BIMSDEVMTL
 

More from MSDEVMTL (20)

Intro grpc.net
Intro  grpc.netIntro  grpc.net
Intro grpc.net
 
Grpc and asp.net partie 2
Grpc and asp.net partie 2Grpc and asp.net partie 2
Grpc and asp.net partie 2
 
Property based testing
Property based testingProperty based testing
Property based testing
 
Improve cloud visibility and cost in Microsoft Azure
Improve cloud visibility and cost in Microsoft AzureImprove cloud visibility and cost in Microsoft Azure
Improve cloud visibility and cost in Microsoft Azure
 
Return on Ignite 2019: Azure, .NET, A.I. & Data
Return on Ignite 2019: Azure, .NET, A.I. & DataReturn on Ignite 2019: Azure, .NET, A.I. & Data
Return on Ignite 2019: Azure, .NET, A.I. & Data
 
Asp.net core 3
Asp.net core 3Asp.net core 3
Asp.net core 3
 
MSDEVMTL Informations 2019
MSDEVMTL Informations 2019MSDEVMTL Informations 2019
MSDEVMTL Informations 2019
 
Common features in webapi aspnetcore
Common features in webapi aspnetcoreCommon features in webapi aspnetcore
Common features in webapi aspnetcore
 
Groupe Excel et Power BI - Rencontre du 25 septembre 2018
Groupe Excel et Power BI  - Rencontre du 25 septembre 2018Groupe Excel et Power BI  - Rencontre du 25 septembre 2018
Groupe Excel et Power BI - Rencontre du 25 septembre 2018
 
Api gateway
Api gatewayApi gateway
Api gateway
 
Common features in webapi aspnetcore
Common features in webapi aspnetcoreCommon features in webapi aspnetcore
Common features in webapi aspnetcore
 
Stephane Lapointe: Governance in Azure, keep control of your environments
Stephane Lapointe: Governance in Azure, keep control of your environmentsStephane Lapointe: Governance in Azure, keep control of your environments
Stephane Lapointe: Governance in Azure, keep control of your environments
 
Eric Routhier: Garder le contrôle sur vos coûts Azure
Eric Routhier: Garder le contrôle sur vos coûts AzureEric Routhier: Garder le contrôle sur vos coûts Azure
Eric Routhier: Garder le contrôle sur vos coûts Azure
 
Data science presentation
Data science presentationData science presentation
Data science presentation
 
Michel Ouellette + Gabriel Lainesse: Process Automation & Data Analytics at S...
Michel Ouellette + Gabriel Lainesse: Process Automation & Data Analytics at S...Michel Ouellette + Gabriel Lainesse: Process Automation & Data Analytics at S...
Michel Ouellette + Gabriel Lainesse: Process Automation & Data Analytics at S...
 
Open id connect, azure ad, angular 5, web api core
Open id connect, azure ad, angular 5, web api coreOpen id connect, azure ad, angular 5, web api core
Open id connect, azure ad, angular 5, web api core
 
Yoann Clombe : Fail fast, iterate quickly with power bi and google analytics
Yoann Clombe : Fail fast, iterate quickly with power bi and google analyticsYoann Clombe : Fail fast, iterate quickly with power bi and google analytics
Yoann Clombe : Fail fast, iterate quickly with power bi and google analytics
 
CAE: etude de cas - Rolling Average
CAE: etude de cas - Rolling AverageCAE: etude de cas - Rolling Average
CAE: etude de cas - Rolling Average
 
CAE: etude de cas
CAE: etude de casCAE: etude de cas
CAE: etude de cas
 
Dan Edwards : Data visualization best practices with Power BI
Dan Edwards : Data visualization best practices with Power BIDan Edwards : Data visualization best practices with Power BI
Dan Edwards : Data visualization best practices with Power BI
 

Recently uploaded

Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 

Recently uploaded (20)

Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 

C sharp 8.0 new features

  • 1. C# 8.0 new features
  • 2. Who Am I? Miguel has over 10 years of experience with Microsoft Technologies. Specialized with many things in the Microsoft ecosystem, including C#, F#, and Azure, he likes to blog about his engineering notes and technology in general. He is also very involved in the Montréal msdevmtl community where he is a co-organizer. NEXUS INNOVATIONS - PRÉSENTATION 2 https://blog.miguelbernard.com https://www.linkedin.com/in/miguelbernard/ @MiguelBernard88 https://github.com/mbernard
  • 3. New features • Readonly members • Default interface methods • Pattern matching enhancements • Using declarations • Static local functions • Disposable ref structs • Nullable reference types • Asynchronous streams • Indices and ranges • Null-coalescing assignment • Unmanaged constructed types • Stackalloc in nested expressions • Enhancement of interpolated verbatim strings NEXUS INNOVATIONS - PRÉSENTATION 3
  • 4. Nullable reference types To enable it • In .csproj • <LangVersion>8.0</LangVersion> • <Nullable>Enable</Nullable> • In code • #nullable enable • #nullable restore NEXUS INNOVATIONS - PRÉSENTATION 4
  • 5. Nullable reference types ? nullable operator ! Null forgiving operator i.e. NEXUS INNOVATIONS - PRÉSENTATION 5 string? a = null; a!.Length;
  • 6. Nullable reference types DEMO NEXUS INNOVATIONS - PRÉSENTATION 6
  • 7. Pattern matching enhancements Use case of a Toll service V1 -Price per vehicle type • 🚗Car -> 2$ • 🚕Taxi -> 3.50$ • 🚌Bus -> 5$ • 🚚Truck -> 10$ NEXUS INNOVATIONS - PRÉSENTATION 7
  • 8. Pattern matching enhancements V2 - Price considering occupancy • Car and taxi • No passengers -> +0.50 $ • 2 passengers -> -0.50 $ • 3 or more passengers -> -1$ NEXUS INNOVATIONS - PRÉSENTATION 8
  • 9. Pattern matching enhancements V3 - Price considering occupancy • Car and taxi • No passengers -> +0.50 $ • 2 passengers -> -0.50 $ • 3 or more passengers -> -1$ • Bus • Less than 50% full -> +2$ • More than 90% full -> -1$ NEXUS INNOVATIONS - PRÉSENTATION 9
  • 10. Pattern matching enhancements V4 - Price considering weight • > 5000 lbs -> +5$ • < 3000 lbs -> -2$ NEXUS INNOVATIONS - PRÉSENTATION 10
  • 11. Pattern matching enhancements V5 – Refactor Car and Taxi! NEXUS INNOVATIONS - PRÉSENTATION 11
  • 12. Asynchronous streams To have an async stream you need 3 properties • It’s declared with the ‘async’ modifier • It returns an IAsyncEnumerable<T> • The method contains ‘yield return’ statements NEXUS INNOVATIONS - PRÉSENTATION 12
  • 13. Asynchronous streams NEXUS INNOVATIONS - PRÉSENTATION 13 internal async IAsyncEnumerable<int> GenerateSequence() { for (int i = 0; i < 20; i++) { // every 3 elements, wait 2 seconds: if (i % 3 == 0) await Task.Delay(3000); yield return i; } } internal async Task<int> ConsumeStream() { await foreach (var number in GenerateSequence()) { Console.WriteLine($"The time is {DateTime.Now:hh:mm:ss}. Retrieved {number}"); } return 0; }
  • 14. Indices and ranges New operators • The index from end operator ^, which specifies that an index is relative to the end of the sequence • The range operator .., which specifies the start and end of a range as its operands NEXUS INNOVATIONS - PRÉSENTATION 14
  • 15. Indices and ranges Notes • The ^0 index is the same as sequence[sequence.Length]. • Note that sequence[^0] does throw an exception, just as sequence[sequence.Length] does • For any number n, the index ^n is the same as sequence.Length – n • The range [0..^0] represents the entire range, just as [0..sequence.Length] represents the entire range. NEXUS INNOVATIONS - PRÉSENTATION 15
  • 16. Indices and ranges NEXUS INNOVATIONS - PRÉSENTATION 16 private string[] words = new string[] { // index from start index from end "The", // 0 ^9 "quick", // 1 ^8 "brown", // 2 ^7 "fox", // 3 ^6 "jumped", // 4 ^5 "over", // 5 ^4 "the", // 6 ^3 "lazy", // 7 ^2 "dog" // 8 ^1 };
  • 17. Indices and ranges NEXUS INNOVATIONS - PRÉSENTATION 17 var allWords = words[..]; // contains "The" through "dog". var firstPhrase = words[..4]; // contains "The" through "fox" var lastPhrase = words[6..]; // contains "the, "lazy" and "dog" var lazyDog = words[^2..^0]; Index the = ^3; words[the]; Range phrase = 1..4; words[phrase];
  • 18. Default interface methods Demo! NEXUS INNOVATIONS - PRÉSENTATION 18
  • 19. Static local functions NEXUS INNOVATIONS - PRÉSENTATION 19 int M() { int y = 5; int x = 7; return Add(x, y); static int Add(int left, int right) => left + right; } You can now add the static modifier to local functions to ensure that local function doesn't capture (reference) any variables from the enclosing scope. Doing so generates CS8421, "A static local function can't contain a reference to <variable>."
  • 20. Null-coalescing assignment C# 8.0 introduces the null-coalescing assignment operator ??=. You can use the ??= operator to assign the value of its right-hand operand to its left-hand operand only if the left-hand operand evaluates to null. NEXUS INNOVATIONS - PRÉSENTATION 20 List<int> numbers = null; int? a = null; (numbers ??= new List<int>()).Add(5); Console.WriteLine(string.Join(" ", numbers)); // output: 5 numbers.Add(a ??= 0); Console.WriteLine(string.Join(" ", numbers)); // output: 5 0 Console.WriteLine(a); // output: 0
  • 21. Using declarations Using variables are automatically disposed at the end of the current scope NEXUS INNOVATIONS - PRÉSENTATION 21 public void Method() { using var file = new StreamWriter(“myFile.txt”); …logic here… } // Disposed here public void Method() { using(var file = new StreamWriter(“myFile.txt”)) { …logic here… } // Disposed here }
  • 22. Enhancement of interpolated verbatim strings Order of the $ and @ tokens in interpolated verbatim strings can be any: both $@"..." and @$"..." are valid interpolated verbatim strings In earlier C# versions, the $ token must appear before the @ token NEXUS INNOVATIONS - PRÉSENTATION 22
  • 23. Readonly members • Only applicable for struct • Advantages • The compilier can now enforce your intent • Doing so will enable to compiler to perform performance optimizations on your code NEXUS INNOVATIONS - PRÉSENTATION 23 public struct Point { public double X { get; set; } public double Y { get; set; } public readonly double Distance => Math.Sqrt(X * X + Y * Y); public readonly override string ToString() => $"({X}, {Y}) is {Distance} from the origin"; }
  • 24. Unmanaged constructed types NEXUS INNOVATIONS - PRÉSENTATION 24 public struct Coords<T> where T : unmanaged { public T X; public T Y; } Span<Coords<int>> coordinates = stackalloc[] { new Coords<int> { X = 0, Y = 0 }, new Coords<int> { X = 0, Y = 3 }, new Coords<int> { X = 4, Y = 0 } };
  • 25. Stackalloc in nested expressions Starting with C# 8.0, if the result of a stackalloc expression is of the Span<T> or ReadOnlySpan<T> type, you can use the stackalloc expression in other expressions NEXUS INNOVATIONS - PRÉSENTATION 25 Span<int> numbers = stackalloc[] { 1, 2, 3, 4, 5, 6 }; var ind = numbers.IndexOfAny(stackalloc[] { 2, 4, 6 ,8 }); Console.WriteLine(ind); // output: 1
  • 26. Disposable ref structs A struct declared with the ref modifier may not implement any interfaces and so can't implement IDisposable. Therefore, to enable a ref struct to be disposed, it must have an accessible `void Dispose()` method. This feature also applies to readonly ref struct declarations. NEXUS INNOVATIONS - PRÉSENTATION 26 ref struct Book { public void Dispose() { } }
  • 27. References • https://github.com/mbernard/csharp8sample • https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8 • https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/default-interface- methods-versions NEXUS INNOVATIONS - PRÉSENTATION 27
  • 28. Questions? Questions? NEXUS INNOVATIONS - PRÉSENTATION 28 https://blog.miguelbernard.com https://www.linkedin.com/in/miguelbernard/ @MiguelBernard88 https://github.com/mbernard
  • 29. 1751 Richardson, suite, 4.500 H3K 1G6, Montréa, Canada NEXUS INNOVATIONS - PRÉSENTATION 29

Editor's Notes

  1. Ca deviant tres interessant quand on a plusieurs using de suite
  2. A generic struct may be the source of both unmanaged and not unmanaged constructed types. The preceding example defines a generic struct Coords<T> and presents the examples of unmanaged constructed types. The example of not an unmanaged type is Coords<object>. It's not unmanaged because it has the fields of the object type, which is not unmanaged. If you want all constructed types to be unmanaged types, use the unmanaged constraint in the definition of a generic struct: