SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
MANOJ KUMAR SHARMA
Platform & Developer Evangelist
mailme@manojkumarsharma.com
http://www.linkedin.com/in/contact4manoj
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission.
1
What’s new in C# 8.0
2
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Introduction
What’s new in C# 8.0
3
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
How to check available C# versions?
• Open Developer Command Prompt
 csc -langversion:?
Developer Command Prompt for VS2019Developer Command Prompt for VS2019
4
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Default Language Version
The Compiler determines
the DEFAULT Language
Version.
Target framework Version Default C# language version
.NET Core 3.x C# 8.0
.NET Core 2.x C# 7.3
.NET Standard 2.1 C# 8.0
.NET Standard 2.0 C# 7.3
.NET Standard 1.x C# 7.3
.NET Framework all C# 7.3
5
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
How to use C# 8.0
• To override the DEFAULT version to use C# 8.0:
• Edit the .csproj file
...
<PropertyGroup>
...
<OutputType>Exe</OutputType>
...
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<LangVersion>8.0</LangVersion>
...
</PropertyGroup>
...
.csproj.csproj
6
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Support modern cloud scenarios
• Async enumerables
• More patterns in more places
• Default interface members
• Indices and Ranges
7
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Increase your productivity
• Using statement
• Static local functions
• Readonly members
• Null coalescing assignment
• Unmanaged constraint
• Interpolated verbatim strings
8
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
What’s new in C# 8.0
• Readonly members
• Default interface methods
• Pattern matching enhancements
• Switch expressions
• Property patterns
• Tuple patterns
• Positional patterns
• 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
9
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Some of them….
What’s new in C# 8.0
10
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Readonly members
• Add the readonly modifier to any structure member.
• Indicates that the member does not modify state.
• It's more granular than applying the readonly modifier to a struct declaration.
• This feature lets you specify your design intent so the compiler can
enforce it, and make optimizations based on that intent.
cs8_con_ReadonlyMembers
11
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Default Interface Methods
• Used to define default method
implementations to members
implementing the Interface.
• Change Interfaces without breaking
changes
• Reusability of methods in
independent classes
• Based on Java’s Default Methods
• Extensions are now possible!
• Alternative to Extension Methods
• Runtime polymorphism
• Allowed Modifiers:
private, protected, internal,
public, virtual, abstract, override,
sealed, static, external
cs8_con_DefaultInterfaceMethods
12
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Ranges and Indices
• Based upon two new Types:
• System.Index
• Represents an index for a sequence of objects in collection
• The index from end operator ( ^ ) (known as “hat” operator)
• Works on Countable Types having Length / Count and an Instance Indexer with int
• System.Range
• Represents a sub-range of a sequence of objects in the collection
• The range operator ( .. ) specifies the start and end of a range as its operands
• Works on Countable Types having Length / Count and Slice() method with two int
• NOTE:
• Ranges is not supported by List<T>
• The element selection is:
• 0-based if you are counting from the beginning, and
• 1-based if you are counting from the end.
cs8_con_RangesAndIndices
13
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Null Reference Types
• Sir Charles Antony Richard Hoare
• Inventor of QuickSort Algorithm in 1959/1960
• In 2009 at QCon, London,
apologized for inventing Null Reference
• The most common .NET Exception – NullReferenceException
I call it my billion-dollar mistake. It was the invention of the null reference in
1965. At that time, I was designing the first comprehensive type system for
references in an object oriented language (ALGOL W). My goal was to ensure
that all use of references should be absolutely safe, with checking performed
automatically by the compiler. But I couldn't resist the temptation to put in a
null reference, simply because it was so easy to implement….
14
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Null Reference Types
• In C# 5.0: Coalescing Operator ( ?? ) was introduced to provide
Default Values for null
decimal basicSalary;
private void AddBonus(decimal? percent)
{
// Would throw NullReferenceException if percent is null!
basicSalary += (basicSalary * percent.Value);
// Solution: Check for null, before consumption
basicSalary += percent.HasValue ? (basicSalary * percent.Value) : 0M;
// Solution: C# 5.0 approach
basicSalary += basicSalary * (percent ?? 0M);
}
Employee.csEmployee.cs
15
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Null Reference Types
• In C# 6.0:
Null-Check Operator / Null-Safe Operator ( ?. ) simplified code
• NOTE:
( ?. ) returns a nullable value
See https://enterprisecraftsmanship.com/posts/3-misuses-of-operator-in-c-6/
for more information to understand when and how to use efficiently.
int? productsCount = products?.Length;
.cs.cs
16
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
How to use Nullable Reference Types
• To enable Nullable Reference Types in C# 8.0 Project:
...
<PropertyGroup>
...
<OutputType>Exe</OutputType>
...
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
...
</PropertyGroup>
...
.csproj.csproj
17
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
How to use Nullable Reference Types
• To enable at the file level:
• To disable at the file level:
#nullable enable
using System;
...
.cs.cs
#nullable disable
using System;
...
.cs.cs
18
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Nullable Reference Types
• To help mitigate NullReferenceException with Compiler Warnings:
( ?? ) Null-Coalescing Operator C# 5.0
( ! ) Postfix Unary Null-Forgiving Operator C# 8.0
( ??= ) Null-Coalescing Assignment Operator C# 8.0
( ?. ) Null-Coalescing Conditional Operator a.k.a. Null-Safe Operator C# 6.0
• Helps to find bugs; Flow analysis tracks nullable reference variables
See also:
• https://docs.microsoft.com/en-us/dotnet/csharp/nullable-attributes
• https://www.meziantou.net/csharp-8-nullable-reference-types.htm
• https://docs.microsoft.com/en-us/dotnet/csharp/nullable-attributes
• https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types
cs8_con_NullableReferenceTypes
19
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Nullable Reference Types
• Recommended Guidelines for adoption:
• Library developers – Nullable adoption phase before .NET 5
• App developers – nullability on your own pace
• Annotate new APIs
• Do not remove argument validation
• Parameter is non-nullable if parameters are checked
(ArgumentNullException)
• Parameter is nullable if documented to accept null
• Prefer nullable over non-nullable with disagreements
20
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Async Streams
• so far: async / await returns a result
• Async streams extends async / await stream of results
• Asynchronous data sources from the consumer to be controlled
• Alternative to Reactive Extensions (Rx) for .NET
System.Reactive (https://github.com/dotnet/reactive)
A library for composing asynchronous and event-based programs using
observable sequences and LINQ-style query operators
USE CASE:
• Streaming from Server to Client
• Streaming from Client to Server
21
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Async Streams
public interface IAsyncEnumerator<[NullableAttribute(2)] out T>
: IAsyncDisposable
{
T Current { get; }
ValueTask<bool> MoveNextAsync();
}
System.Collections.Generic.IAsyncEnumerator.csSystem.Collections.Generic.IAsyncEnumerator.cs
public interface IAsyncEnumerable<out T>
{
IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default);
}
System.Collections.Generic.IAsyncEnumerable.csSystem.Collections.Generic.IAsyncEnumerable.cs
public interface IAsyncDisposable
{
ValueTask DisposeAsync();
}
System.IAsyncDisposable.csSystem.IAsyncDisposable.cs
cs8_con_AsyncStreams
22
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Summary
What’s new in C# 8.0
23
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
C# 8.0
Safe
Nullable and non-nullable
reference types help you write
safer code. Declare your intent
more clearly.
Modern
Async streams for modern
workloads like Cloud & IoT
communication.
Easily work with cloud scale
datasets using Indexes and
Ranges.
Productive
Write less code using Patterns.
Protect data with readonly
members.
Improved using statements for
resource management.
24
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be
reproduced in any form without an express written permission.
Further Learning…
• What’s New in C# 8.0
https://aka.ms/new-csharp
• .NET CONF 2019 official website
https://www.dotnetconf.net
• Videos on Youtube:
http://bit.ly/bdotnetconf2019
• All .NET CONF 2019 Materials:
https://github.com/dotnet-presentations/dotnetconf2019
• To edit “Edit Project File” and other useful extensions in VS2019
Power Commands for Visual Studio – Microsoft DevLabs
https://marketplace.visualstudio.com/items?itemName=VisualSt
udioPlatformTeam.PowerCommandsforVisualStudio
MANOJ KUMAR SHARMA
Platform & Developer Evangelist
mailme@manojkumarsharma.com
http://www.linkedin.com/in/contact4manoj
Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved.
This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission.
25
Thank You!

Mais conteúdo relacionado

Mais procurados

PHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonPHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonHaim Michael
 
Comparison of Programming Platforms
Comparison of Programming PlatformsComparison of Programming Platforms
Comparison of Programming PlatformsAnup Hariharan Nair
 
Java Fundamentals in Mule
Java Fundamentals in MuleJava Fundamentals in Mule
Java Fundamentals in MuleAnand kalla
 
java training institute course class indore
java training institute course class indorejava training institute course class indore
java training institute course class indoreFuture Multimedia
 
Introduction to flutter's basic concepts
Introduction to flutter's basic conceptsIntroduction to flutter's basic concepts
Introduction to flutter's basic conceptsKumaresh Chandra Baruri
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.netJanbask ItTraining
 
Java language is different from other programming languages, How?
Java language is different  from other programming languages, How?Java language is different  from other programming languages, How?
Java language is different from other programming languages, How?Gyanguide1
 
Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1willmation
 
6 Weeks Summer Training on Java By SSDN Technologies
6 Weeks Summer Training on Java By SSDN Technologies6 Weeks Summer Training on Java By SSDN Technologies
6 Weeks Summer Training on Java By SSDN TechnologiesDavid Son
 
Tl Recruit360 Features V1.3
Tl Recruit360 Features V1.3Tl Recruit360 Features V1.3
Tl Recruit360 Features V1.3ryanpmay
 
PHP Interview Questions and Answers | Edureka
PHP Interview Questions and Answers | EdurekaPHP Interview Questions and Answers | Edureka
PHP Interview Questions and Answers | EdurekaEdureka!
 

Mais procurados (19)

PHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonPHP, Java EE & .NET Comparison
PHP, Java EE & .NET Comparison
 
Comparison of Programming Platforms
Comparison of Programming PlatformsComparison of Programming Platforms
Comparison of Programming Platforms
 
Let's talk about certification: SCJA
Let's talk about certification: SCJALet's talk about certification: SCJA
Let's talk about certification: SCJA
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Dacj 2-2 a
Dacj 2-2 aDacj 2-2 a
Dacj 2-2 a
 
Java Fundamentals in Mule
Java Fundamentals in MuleJava Fundamentals in Mule
Java Fundamentals in Mule
 
Java for C++ programers
Java for C++ programersJava for C++ programers
Java for C++ programers
 
Curso de Programación Java Básico
Curso de Programación Java BásicoCurso de Programación Java Básico
Curso de Programación Java Básico
 
java training institute course class indore
java training institute course class indorejava training institute course class indore
java training institute course class indore
 
Introduction to flutter's basic concepts
Introduction to flutter's basic conceptsIntroduction to flutter's basic concepts
Introduction to flutter's basic concepts
 
java token
java tokenjava token
java token
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.net
 
Java language is different from other programming languages, How?
Java language is different  from other programming languages, How?Java language is different  from other programming languages, How?
Java language is different from other programming languages, How?
 
Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1Behaviour Driven Development V 0.1
Behaviour Driven Development V 0.1
 
Java notes
Java notesJava notes
Java notes
 
6 Weeks Summer Training on Java By SSDN Technologies
6 Weeks Summer Training on Java By SSDN Technologies6 Weeks Summer Training on Java By SSDN Technologies
6 Weeks Summer Training on Java By SSDN Technologies
 
Tl Recruit360 Features V1.3
Tl Recruit360 Features V1.3Tl Recruit360 Features V1.3
Tl Recruit360 Features V1.3
 
Raptor 2
Raptor 2Raptor 2
Raptor 2
 
PHP Interview Questions and Answers | Edureka
PHP Interview Questions and Answers | EdurekaPHP Interview Questions and Answers | Edureka
PHP Interview Questions and Answers | Edureka
 

Semelhante a Whats Newi in C# 8.0

Review Paper on Online Java Compiler
Review Paper on Online Java CompilerReview Paper on Online Java Compiler
Review Paper on Online Java CompilerIRJET Journal
 
How to design good api
How to design good apiHow to design good api
How to design good apiOsama Shakir
 
IRJET- Build a Secure Web based Code Editor for C Programming Language
IRJET-  	  Build a Secure Web based Code Editor for C Programming LanguageIRJET-  	  Build a Secure Web based Code Editor for C Programming Language
IRJET- Build a Secure Web based Code Editor for C Programming LanguageIRJET Journal
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIsNLJUG
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Peter Hendriks
 
Presentation
PresentationPresentation
Presentationbhasula
 
Trouble with Performance Debugging? Not Anymore with Choreo, the AI-Assisted ...
Trouble with Performance Debugging? Not Anymore with Choreo, the AI-Assisted ...Trouble with Performance Debugging? Not Anymore with Choreo, the AI-Assisted ...
Trouble with Performance Debugging? Not Anymore with Choreo, the AI-Assisted ...WSO2
 
How To Design A Good A P I And Why It Matters G O O G L E
How To Design A Good  A P I And Why It Matters    G O O G L EHow To Design A Good  A P I And Why It Matters    G O O G L E
How To Design A Good A P I And Why It Matters G O O G L Eguestbe92f4
 
Faridabad MuleSoft Meetup Group (1).pdf
Faridabad MuleSoft Meetup Group (1).pdfFaridabad MuleSoft Meetup Group (1).pdf
Faridabad MuleSoft Meetup Group (1).pdfRohitSingh585124
 
How to become a Rational Developer for IBM i Power User
How to become a Rational Developer for IBM i Power UserHow to become a Rational Developer for IBM i Power User
How to become a Rational Developer for IBM i Power UserStrongback Consulting
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptxSanuSan3
 
C# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayC# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayAfonso Macedo
 
Content Strategy and Developer Engagement for DevPortals
Content Strategy and Developer Engagement for DevPortalsContent Strategy and Developer Engagement for DevPortals
Content Strategy and Developer Engagement for DevPortalsAxway
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleikram_ahamed
 

Semelhante a Whats Newi in C# 8.0 (20)

Advanced angular
Advanced angularAdvanced angular
Advanced angular
 
Review Paper on Online Java Compiler
Review Paper on Online Java CompilerReview Paper on Online Java Compiler
Review Paper on Online Java Compiler
 
How to design good api
How to design good apiHow to design good api
How to design good api
 
IRJET- Build a Secure Web based Code Editor for C Programming Language
IRJET-  	  Build a Secure Web based Code Editor for C Programming LanguageIRJET-  	  Build a Secure Web based Code Editor for C Programming Language
IRJET- Build a Secure Web based Code Editor for C Programming Language
 
Linq in asp.net
Linq in asp.netLinq in asp.net
Linq in asp.net
 
Anagha
AnaghaAnagha
Anagha
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
Presentation
PresentationPresentation
Presentation
 
Trouble with Performance Debugging? Not Anymore with Choreo, the AI-Assisted ...
Trouble with Performance Debugging? Not Anymore with Choreo, the AI-Assisted ...Trouble with Performance Debugging? Not Anymore with Choreo, the AI-Assisted ...
Trouble with Performance Debugging? Not Anymore with Choreo, the AI-Assisted ...
 
How To Design A Good A P I And Why It Matters G O O G L E
How To Design A Good  A P I And Why It Matters    G O O G L EHow To Design A Good  A P I And Why It Matters    G O O G L E
How To Design A Good A P I And Why It Matters G O O G L E
 
Faridabad MuleSoft Meetup Group (1).pdf
Faridabad MuleSoft Meetup Group (1).pdfFaridabad MuleSoft Meetup Group (1).pdf
Faridabad MuleSoft Meetup Group (1).pdf
 
How to become a Rational Developer for IBM i Power User
How to become a Rational Developer for IBM i Power UserHow to become a Rational Developer for IBM i Power User
How to become a Rational Developer for IBM i Power User
 
Keynoteof A P I
Keynoteof A P IKeynoteof A P I
Keynoteof A P I
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptx
 
C# Fundamental
C# FundamentalC# Fundamental
C# Fundamental
 
C# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayC# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy today
 
Content Strategy and Developer Engagement for DevPortals
Content Strategy and Developer Engagement for DevPortalsContent Strategy and Developer Engagement for DevPortals
Content Strategy and Developer Engagement for DevPortals
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
Mule ESB Intro
Mule ESB IntroMule ESB Intro
Mule ESB Intro
 

Último

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 

Último (20)

Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

Whats Newi in C# 8.0

  • 1. MANOJ KUMAR SHARMA Platform & Developer Evangelist mailme@manojkumarsharma.com http://www.linkedin.com/in/contact4manoj Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. 1 What’s new in C# 8.0
  • 2. 2 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Introduction What’s new in C# 8.0
  • 3. 3 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. How to check available C# versions? • Open Developer Command Prompt  csc -langversion:? Developer Command Prompt for VS2019Developer Command Prompt for VS2019
  • 4. 4 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Default Language Version The Compiler determines the DEFAULT Language Version. Target framework Version Default C# language version .NET Core 3.x C# 8.0 .NET Core 2.x C# 7.3 .NET Standard 2.1 C# 8.0 .NET Standard 2.0 C# 7.3 .NET Standard 1.x C# 7.3 .NET Framework all C# 7.3
  • 5. 5 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. How to use C# 8.0 • To override the DEFAULT version to use C# 8.0: • Edit the .csproj file ... <PropertyGroup> ... <OutputType>Exe</OutputType> ... <TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <LangVersion>8.0</LangVersion> ... </PropertyGroup> ... .csproj.csproj
  • 6. 6 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Support modern cloud scenarios • Async enumerables • More patterns in more places • Default interface members • Indices and Ranges
  • 7. 7 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Increase your productivity • Using statement • Static local functions • Readonly members • Null coalescing assignment • Unmanaged constraint • Interpolated verbatim strings
  • 8. 8 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. What’s new in C# 8.0 • Readonly members • Default interface methods • Pattern matching enhancements • Switch expressions • Property patterns • Tuple patterns • Positional patterns • 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
  • 9. 9 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Some of them…. What’s new in C# 8.0
  • 10. 10 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Readonly members • Add the readonly modifier to any structure member. • Indicates that the member does not modify state. • It's more granular than applying the readonly modifier to a struct declaration. • This feature lets you specify your design intent so the compiler can enforce it, and make optimizations based on that intent. cs8_con_ReadonlyMembers
  • 11. 11 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Default Interface Methods • Used to define default method implementations to members implementing the Interface. • Change Interfaces without breaking changes • Reusability of methods in independent classes • Based on Java’s Default Methods • Extensions are now possible! • Alternative to Extension Methods • Runtime polymorphism • Allowed Modifiers: private, protected, internal, public, virtual, abstract, override, sealed, static, external cs8_con_DefaultInterfaceMethods
  • 12. 12 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Ranges and Indices • Based upon two new Types: • System.Index • Represents an index for a sequence of objects in collection • The index from end operator ( ^ ) (known as “hat” operator) • Works on Countable Types having Length / Count and an Instance Indexer with int • System.Range • Represents a sub-range of a sequence of objects in the collection • The range operator ( .. ) specifies the start and end of a range as its operands • Works on Countable Types having Length / Count and Slice() method with two int • NOTE: • Ranges is not supported by List<T> • The element selection is: • 0-based if you are counting from the beginning, and • 1-based if you are counting from the end. cs8_con_RangesAndIndices
  • 13. 13 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Null Reference Types • Sir Charles Antony Richard Hoare • Inventor of QuickSort Algorithm in 1959/1960 • In 2009 at QCon, London, apologized for inventing Null Reference • The most common .NET Exception – NullReferenceException I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement….
  • 14. 14 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Null Reference Types • In C# 5.0: Coalescing Operator ( ?? ) was introduced to provide Default Values for null decimal basicSalary; private void AddBonus(decimal? percent) { // Would throw NullReferenceException if percent is null! basicSalary += (basicSalary * percent.Value); // Solution: Check for null, before consumption basicSalary += percent.HasValue ? (basicSalary * percent.Value) : 0M; // Solution: C# 5.0 approach basicSalary += basicSalary * (percent ?? 0M); } Employee.csEmployee.cs
  • 15. 15 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Null Reference Types • In C# 6.0: Null-Check Operator / Null-Safe Operator ( ?. ) simplified code • NOTE: ( ?. ) returns a nullable value See https://enterprisecraftsmanship.com/posts/3-misuses-of-operator-in-c-6/ for more information to understand when and how to use efficiently. int? productsCount = products?.Length; .cs.cs
  • 16. 16 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. How to use Nullable Reference Types • To enable Nullable Reference Types in C# 8.0 Project: ... <PropertyGroup> ... <OutputType>Exe</OutputType> ... <TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <LangVersion>8.0</LangVersion> <Nullable>enable</Nullable> ... </PropertyGroup> ... .csproj.csproj
  • 17. 17 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. How to use Nullable Reference Types • To enable at the file level: • To disable at the file level: #nullable enable using System; ... .cs.cs #nullable disable using System; ... .cs.cs
  • 18. 18 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Nullable Reference Types • To help mitigate NullReferenceException with Compiler Warnings: ( ?? ) Null-Coalescing Operator C# 5.0 ( ! ) Postfix Unary Null-Forgiving Operator C# 8.0 ( ??= ) Null-Coalescing Assignment Operator C# 8.0 ( ?. ) Null-Coalescing Conditional Operator a.k.a. Null-Safe Operator C# 6.0 • Helps to find bugs; Flow analysis tracks nullable reference variables See also: • https://docs.microsoft.com/en-us/dotnet/csharp/nullable-attributes • https://www.meziantou.net/csharp-8-nullable-reference-types.htm • https://docs.microsoft.com/en-us/dotnet/csharp/nullable-attributes • https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types cs8_con_NullableReferenceTypes
  • 19. 19 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Nullable Reference Types • Recommended Guidelines for adoption: • Library developers – Nullable adoption phase before .NET 5 • App developers – nullability on your own pace • Annotate new APIs • Do not remove argument validation • Parameter is non-nullable if parameters are checked (ArgumentNullException) • Parameter is nullable if documented to accept null • Prefer nullable over non-nullable with disagreements
  • 20. 20 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Async Streams • so far: async / await returns a result • Async streams extends async / await stream of results • Asynchronous data sources from the consumer to be controlled • Alternative to Reactive Extensions (Rx) for .NET System.Reactive (https://github.com/dotnet/reactive) A library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators USE CASE: • Streaming from Server to Client • Streaming from Client to Server
  • 21. 21 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Async Streams public interface IAsyncEnumerator<[NullableAttribute(2)] out T> : IAsyncDisposable { T Current { get; } ValueTask<bool> MoveNextAsync(); } System.Collections.Generic.IAsyncEnumerator.csSystem.Collections.Generic.IAsyncEnumerator.cs public interface IAsyncEnumerable<out T> { IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default); } System.Collections.Generic.IAsyncEnumerable.csSystem.Collections.Generic.IAsyncEnumerable.cs public interface IAsyncDisposable { ValueTask DisposeAsync(); } System.IAsyncDisposable.csSystem.IAsyncDisposable.cs cs8_con_AsyncStreams
  • 22. 22 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Summary What’s new in C# 8.0
  • 23. 23 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. C# 8.0 Safe Nullable and non-nullable reference types help you write safer code. Declare your intent more clearly. Modern Async streams for modern workloads like Cloud & IoT communication. Easily work with cloud scale datasets using Indexes and Ranges. Productive Write less code using Patterns. Protect data with readonly members. Improved using statements for resource management.
  • 24. 24 Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. Further Learning… • What’s New in C# 8.0 https://aka.ms/new-csharp • .NET CONF 2019 official website https://www.dotnetconf.net • Videos on Youtube: http://bit.ly/bdotnetconf2019 • All .NET CONF 2019 Materials: https://github.com/dotnet-presentations/dotnetconf2019 • To edit “Edit Project File” and other useful extensions in VS2019 Power Commands for Visual Studio – Microsoft DevLabs https://marketplace.visualstudio.com/items?itemName=VisualSt udioPlatformTeam.PowerCommandsforVisualStudio
  • 25. MANOJ KUMAR SHARMA Platform & Developer Evangelist mailme@manojkumarsharma.com http://www.linkedin.com/in/contact4manoj Copyright © 2019-2020 Manoj Kumar Sharma. All rights reserved. This presentation is for training purposes only, and cannot be reproduced in any form without an express written permission. 25 Thank You!