net [core] memory internals...sep 15, 2019  · c# 9.0 candidate: top level statements and member...

21
C# 8+ Visual Studio 2019+ Robert Haken software & cloud architect, HAVIT, s.r.o. [email protected], @RobertHaken, https://knowledge-base.havit.cz + .eu Microsoft MVP: Development, MCT, MCPD: Web, MC: Azure Architect

Upload: others

Post on 31-May-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 8+Visual Studio 2019+

Robert Hakensoftware & cloud architect, HAVIT, [email protected], @RobertHaken, https://knowledge-base.havit.cz + .euMicrosoft MVP: Development, MCT, MCPD: Web, MC: Azure Architect

Page 2: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 8.0

Page 3: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 8.0: Default interface methods

https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md

interface IEnumerable<T>{int Count(){

int count = 0;foreach (var x in this)

count++; return count;}

}

interface IList<T> : IEnumerable<T>{int Count { get; }override int IEnumerable<T>.Count() => this.Count;

}

Page 4: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# vNext

Page 5: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: Primary Constructors, Records

class Person : IEquatable<Person>{

public string First { get; }public string Last { get; }

public Person(string First, string Last) => (this.First, this.Last) = (First, Last);

public void Deconstruct(out string First, out string Last)=> (First, Last) = (this.First, this.Last);

public bool Equals(Person other)=> other != null && First == other.First && Last == other.Last;

public override bool Equals(object obj) => obj is Person other ? Equals(other) : false;public override int GetHashCode() => GreatHashFunction(First, Last);…

}

class Person(string First, string Last);

https://github.com/dotnet/csharplang/blob/master/proposals/records.md

Page 6: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: pattern-based`with ̀expressions

class Point

public readonly int

public readonly int

public Point int this int this new Point

// etc

with

with

Page 7: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: Top level statements and member declarationspublic class Functions

public int // Top-level function

public class Program

static void

Console // Top-level statement

// C# vNext (scripting dialect replacement)

public int // Top-level function

Console // Top-level statement

Page 8: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: Covariantreturntypes

class Compilation

virtual Compilation Options

class CSharpCompilation Compilation

override CSharpCompilation Options

Page 9: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: Nullable-Enhanced Common Type

// C# now

int int null

// C# vNext

int null

// C# vNext – Other implicit conversions?

int myDouble

Page 10: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: Target typed null coalescing (̀ ??̀ ) expression

List int uint

IEnumerable int Array int

long

Page 11: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: and, or, and not patterns

switch

case or

case Point or null

case Point var var and var

Page 12: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: Switch expression as a statement expression

void bool ref int ref string

switch true false null

Page 13: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: allow comparison operators in switch cases

int

switch

case

breakcase

breakcase

break

Page 14: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidate: Native-SizedNumberTypes

https://github.com/dotnet/corefxlab/blob/master/docs/specs/nativesized.md

// nowIntPtr ptr;UIntPtr uptr;IntPtr.Size

// vNextIntN i;UIntN u;FloatN f;

Page 15: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# 9.0 Candidates

Discriminated Unions

StaticDelegates

Module Initializers

deferstatement

Permit attributeson localfunctions

Efficient Params and String Formatting (Span as params, ...)

...and more

https://github.com/dotnet/csharplang/milestone/15

Page 16: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

C# vNext(??): Extension everythingextension Enrollee extends Person{

// static fieldstatic Dictionary<Person, Professor> enrollees = new Dictionary<Person, Professor>();

// instance methodpublic void Enroll(Professor supervisor) { enrollees[this] = supervisor; }

// instance propertypublic Professor Supervisor => enrollees.TryGetValue(this, out var supervisor) ? supervisor : null;

// static propertypublic static ICollection<Person> Students => enrollees.Keys;

// instance constructorpublic Person(string name, Professor supervisor) : this(name) { this.Enroll(supervisor); }

}

Page 17: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

Visual Studio 2019.3+

Page 18: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

Vertical Document Tabs

Page 19: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

Visual Studio Online (“Monaco”)

Page 20: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

Visual Studio Remote Development

Page 21: NET [Core] Memory Internals...Sep 15, 2019  · C# 9.0 Candidate: Top level statements and member declarations public class Functions public int // Top-level function public class

REFERENCES

Demos

https://github.com/hakenr/CSharp8Demo

Blog –HAVIT KnowledgeBase-http://knowledge-base.havit.cz/ + .eu

Twitter -@RobertHaken

YouTube-https://www.youtube.com/user/HAVITcz