C# 10 - A Sneaky Peek 👀

A presentation at Oxford .NET Meetup in August 2021 in by Stuart Lang

Slide 1

Slide 1

C# 10 A Sneaky Peek 👀

Slide 2

Slide 2

HELLO! I am Stuart Lang You can find me at https://stu.dev DMs open!

Slide 3

Slide 3

Quick Recap

Slide 4

Slide 4

C# 9 Recap

Slide 5

Slide 5

C# 9 Recap › › › › Top-level Statements Records Pattern Matching Enhancements Source Generators

Slide 6

Slide 6

› .NET 6 Preview 7 › https://aka.ms/dotnet-download

› LINQPad 6 beta › Go to Edit | Preferences > Query › Check “Use Roslyn Daily build”

› https://sharplab.io › Select the Roslyn branch dropdown › Pick “main”

Slide 7

Slide 7

File Scoped Namespaces 7

Slide 8

Slide 8

Slide 9

Slide 9

Slide 10

Slide 10

Slide 11

Slide 11

Global Usings

Slide 12

Slide 12

Slide 13

Slide 13

Slide 14

Slide 14

Slide 15

Slide 15

Slide 16

Slide 16

Slide 17

Slide 17

Slide 18

Slide 18

Console app

Slide 19

Slide 19

Worker app

Slide 20

Slide 20

Web app

Slide 21

Slide 21

Slide 22

Slide 22

Record Structs

Slide 23

Slide 23

Slide 24

Slide 24

Slide 25

Slide 25

SharpLab Example: https://sharplab.io/#v2:EYLgtghglgdgNAExAagD4AEBMBGAsAKAIHoiA3CAJwAIBnAF0roAUB7GqOqFmKgXipgBTAO5UAwixYUEsCHUE0AFNjiYAlAG5iZSgJGt2nbn1oMKzNhy49hHABZUA3gBk5JgCwBfLfhLpsAJyKQsIGVtyaBAQUggDGUgimFACusXTiktKy8koILMnAADaCVK50cFR5BcWl3ADmkYS+RPQpaRkJ2QqO6ADMlflFJWVOdYJ0GrAcGp5UfQPVw/Wj45Mw057eQA

Slide 26

Slide 26

Slide 27

Slide 27

More on Records Records Deep Dive: What, Why and How - David Wengier - NDC Melbourne 2021: https://www.youtube.com/watch?v=lxwNcg2q1-Y 27

Slide 28

Slide 28

Better Lambdas

Slide 29

Slide 29

Before…

Slide 30

Slide 30

Natural Inferred Types for Lambdas

Slide 31

Slide 31

Explicit Lambda Return Types

Slide 32

Slide 32

Lambda Attributes

Slide 33

Slide 33

Minimal APIs

Slide 34

Slide 34

With our powers combined…

Slide 35

Slide 35

The Simplest API

Slide 36

Slide 36

Source: Damian Edwards

Slide 37

Slide 37

Source: Damian Edwards

Slide 38

Slide 38

Slide 39

Slide 39

Caller Expression Attribute

Slide 40

Slide 40

Caller Attributes Recap › [CallerMemberName] › [CallerFilePath] › [CallerLineNumber]

Slide 41

Slide 41

CallerArgementExpression

Slide 42

Slide 42

Slide 43

Slide 43

Slide 44

Slide 44

String Interpolation Improvements

Slide 45

Slide 45

Const Interpolation

Slide 46

Slide 46

String Interpolation Handler

Slide 47

Slide 47

String Interpolation Handler

Slide 48

Slide 48

String Interpolation Handler

Slide 49

Slide 49

Extended Property Pattern

Slide 50

Slide 50

Extended Property Pattern

Slide 51

Slide 51

Required Properties C# 11

Slide 52

Slide 52

Slide 53

Slide 53

Slide 54

Slide 54

!! (Bang Bang) C# 11

Slide 55

Slide 55

Slide 56

Slide 56

Slide 57

Slide 57

Slide 58

Slide 58

Raw String Literals C# 11

Slide 59

Slide 59

Raw String Literals

Slide 60

Slide 60

Generic Attributes C# 11

Slide 61

Slide 61

Generic Attributes

Slide 62

Slide 62

Static Abstracts in Interfaces In Preview

Slide 63

Slide 63

Slide 64

Slide 64

Slide 65

Slide 65

Slide 66

Slide 66

More Resources › .NET 5 & C# 9 Talk - https://drive.google.com/file/d/1IZg12xyrtsH8OPIfpWYl9zlyIUjAhmmq/view?usp=sharing › C# Language Design - https://github.com/dotnet/csharplang/ › Language Feature Status - https://github.com/dotnet/roslyn/blob/main/docs/Language%20Feature%20Status.md › Mads Torgersen Talk - C# 10 - https://www.youtube.com/watch?v=HCiY2Ubm3yA

Slide 67

Slide 67

THANKS! Any questions? You can find me at: @stuartblang · https://stu.dev