SlideShare une entreprise Scribd logo
1  sur  35
What’s new in .NET
ADRIAN STANULA
What's new in .NET Platform
.NET Architectural Components
What is .NET Standard?
• .NET Standard is a specification, not an implementation
• .NET Standard provides a common base .NET Interface to all platforms that implement it so that no matter which
version of .NET you use you'll always see at least the same base feature set.
• .NET Standard describes what a specific implementation like .NET Core, Mono, Xamarin or .NET 4.6 has to implement
- at minimum - in terms of API surface in order to be compliant with a given version of .NET Standard.
.NET platforms support
The following table lists all versions of .NET Standard and the platforms supported:
• The higher the version, the more APIs are available to you.The lower the version, the more platforms implement it.
• https://docs.microsoft.com/en-us/dotnet/api (see also https://apisof.net)
What’s new in .NET Standard 2.0
.NET Standard under the hood
• When .NET Standard class library
references .NET Framework library it uses
special version of mscorlib.dll that
translates types from .NET Framework to
.NET Standard
• Type forwarding is done for each .NET
Framework assembly
.NET Standard under the hood
• When specific .NET runtime, e.g. .NET
Core class library references .NET
Standard library it uses special version of
netstandard.dll that translates types from
.NET Standard to .NET Core
Migrating to .NET Standard
• .NET Portability Analyzer – plugin toVisual Studio
• https://github.com/Microsoft/dotnet-apiport
What’s new in .NET Core?
• .NET Core 1.1 released
• Official release of .NET Core tools (with change in the tooling layers)
• This shared SDK component is a set of MSBuild targets and associated tasks that are responsible for compiling your
code, publishing it, packing NuGet packages etc.
• Moving away from project.json to .csproj
• CLI commands are translated to MSBuild invocations.
• Visual Studio invokes MSBuild directly
What’s new in Visual Studio 2017
Performance improvements
• A new setup experience
• StartVisual Studio faster (The Performance Center lists all the extensions and tool windows that might slow down the
IDE startup)
• Decrease solution load time
• Faster on-demand loading of extensions
Productivity improvements
• Manage your extensions with Roaming Extensions Manager
• When you use the Roaming Extension Manager, you will notice 3 icon types on your list: Roamed, Roamed & Installed, Installed
• Live architecture dependency validation
• Live UnitTesting
Visual Studio IDE enhancements
• View and navigate code with StructureVisualizer
• Experience improved navigation controls
• GoTo (Ctrl+F12) – navigate from any base type or member to its
various implementations.
• GoTo All (Ctrl+T or Ctrl+,) – navigate directly to any
file/type/member/symbol declaration.You can filter your result list or
use the query syntax (for example, “f searchTerm” for files, “t
searchTerm” for types, etc.).
• Find All References (Shift+F12) – with syntax colorization, you can
group FindAll Reference results by a combination of project,
definition, and path.You can also “lock” results so that you can
continue to find other references without losing your original results.
• Indent Guides – dotted, gray vertical lines act as landmarks in code
to provide context within your frame of view.
• Live edit and reload of .csproj file
Debugging and Diagnostics
• Run to Click
• New Exception Helper
Docker Containers support
• Develop, Run, Debug, Update your Web & Console Applications in a Docker Container
• Multi-container debugging
• Edit & Refresh of code
• Publish to Azure App Service
What’s new in C# 7.0
New C# language features
• More expression-bodied members
• throw Expressions
• Generalized async return types
• Numeric literal syntax improvements
• out variables
• Tuples
• Pattern Maching
• ref locals and returns
• Local Functions
out variables
int numericResult;
if (!int.TryParse(input, out numericResult))
{
return 0;
}
return numericResult;
if (!int.TryParse(input, out var numericResult))
{
return 0;
}
return numericResult;
• Previously, you would need to separate the declaration of the out variable and its initialization into two different
statements:
• You can now declare out variables in the argument list of a method call, rather than writing a separate declaration
statement:
• The code is easier to read.
• No need to assign an initial value.
• Support for explicit type as well as var
Tuples creation
• Unnamed tuple:
• Named tuple:
• The new tuples features require the System.ValueTuple type. It can be referenced via NuGet.
var unnamed = ("one", 10);
Console.WriteLine(unnamed.Item1 + unnamed.Item2);
var named = (First: "one", Second: 10);
Console.WriteLine(named.First + named.Second);
(string First, int Second) named = ("one", 10);
Console.WriteLine(named.First + named.Second);
(string First, int Second) named = (A: "one", B: 10);
Console.WriteLine(named.First + unnamed.Second);
Tuples as method return values
• Methods can return tuple results:
private (string First, int Second) GetResult()
{
string first = "one";
int second = 10;
return (first, second);
}
private (string First, int Second) GetResult()
{
var result = (First: "one", Second: 10);
return result;
}
var result = GetResult();
Console.WriteLine(result.First + result.Second);
(double first, var second) = GetResult();
Console.WriteLine(first + second);
private (string First, int Second) GetResult()
{
var result = new Tuple<string, int>("one", 10);
return result; //THIS WILL NOT COMPILE
}
private (string First, int Second) GetResult()
{
var (first, second) = new Tuple<string, int>("one", 10);
return (first, second);
}
• Method result can be assigned to single value or deconstructed:
Tuples as method return values
• Methods can return generic types with tuple:
private IEnumerable<(string First, int Second)> GetResult()
{
yield return ("one", 10);
}
• As well as array of tuple values:
IEnumerable<(string First, int Second)> result = GetResult();
IEnumerable<(string, int)> result2 = GetResult();
var result3 = GetResult();
private (string First, int Second)[] GetResult()
{
return new (string, int)[] {("one", 10)};
}
(string First, int Second)[] result = GetResult();
(string, int)[] result2 = GetResult();
var result3 = GetResult();
Tuples - deconstruction
• Reconstructing a tuple:
• Deconstructing user defined types:
(string first, int second) = GetTupleResult();
var (first, second) = GetTupleResult();
public class Person
{
public string FirstName { get; }
public string LastName { get; }
public void Deconstruct(out string firstName, out string lastName)
{
firstName = FirstName;
lastName = LastName;
}
}
var p = new Person("Althea", "Goodwin");
var (first, last) = p;
• Deconstructing using extension method:
public static class PersonExtensions
{
public static void Deconstruct(this Person person,
out string firstName, out string lastName)
{
firstName = person.FirstName;
lastName = person.LastName;
}
}
Pattern Matching
if (shape is Square)
{
var s = shape as Square;
return s.Side * s.Side;
}
• is operator:
• Pattern matching switch statement :
• The order of the case expressions now matters.
• If you accidentally order match expressions such that a less
explicit case has already been handled, the compiler will flag that
and generate an error.
• The default case is always evaluated last, regardless of the order it
appears in the source.
if (shape is Square s)
{
return s.Side * s.Side;
}
• The is type pattern expression:
switch (shape)
{
case 0:
return 0;
case int val:
return val^2;
case Square s when s.Side == 0:
case Triangle t when t.Base == 0 || t.Height == 0:
return 0;
case Square s:
return s.Side * s.Side;
case Triangle t:
return t.Base * t.Height * 2;
case null:
throw new ArgumentNullException(nameof(shape));
default:
throw new ArgumentException(nameof(shape));
}
ref locals and returns
public static ref int Find(int number, int[] numbers)
{
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] == number)
{
return ref numbers[i]; // return the storage location, not the value
//return numbers[i]; // this will not compile
}
}
throw new InvalidOperationException("Not found");
}
• Just like you can pass things by reference (with the ref modifier) in C#, you can now return them by reference, and also
store them by reference in local variables.
• You could only accomplish this by using unsafe code and returning a pointer to an int in previous versions.
• When you declare that a method returns a ref variable, you must also add the ref keyword to each return statement.
That indicates return by reference, and helps developers reading the code later remember that the method returns by
reference.
int[] array = { 1, 15, -39, 0, 7, 14, -12 };
ref int place = ref Find(7, array); // gets reference to 7's place in the array
place = 9; // replaces 7 with 9 in the array
Console.WriteLine(array[4]); // prints 9
ref locals and returns
var place = Find(7, array); // in this case 7 is printed
• The variable place is an int, not a ref int.The var keyword enables the compiler to specify the type, but will not
implicitly add the ref modifier. Instead, the value referred to by the ref return is copied to the variable on the left-hand
side of the assignment. The variable is not a ref local.
• You must initialize a ref variable when it is declared, you cannot split the declaration and the initialization.
int place = Find(7, array); // in this case 7 is printed
var place = ref Find(7, array); // this will not compile
ref int place = Find(7, array); // this will not compile
ref locals and returns
• You cannot assign a value to a ref variable. That disallows statements like
• You cannot return a ref to a variable whose lifetime does not extend beyond the execution of the method.
That means you cannot return a reference to a local variable, or similar scope.
ref int i = sequence.Count();
The C# language has two other rules that protect you from misusing the ref locals and returns:
These rules ensure that you cannot accidentally mix value variables and reference variables. They also ensure
that you cannot have a reference variable refer to storage that is a candidate for garbage collection.
Local functions
• Used in public iterator methods:
• When checks and logic are in the same method exceptions are not thrown when method is invoked, but only when
result is iterated (because it is iterator method)
• When checks are in public method and logic in private then exceptions are thrown when the method is invoked
(because it is no longer an iterator method), but programmer is able to invoke private method without checks
• When logic is in local function then exception is thrown when method is invoked and programmer is not able to invoke
logic from local function without checks
public static IEnumerable<char> AlphabetSubset(char start, char end)
{
if ((start < 'a') || (start > 'z'))
throw new ArgumentOutOfRangeException(paramName: nameof(start), message: "start must be a letter");
if ((end < 'a') || (end > 'z'))
throw new ArgumentOutOfRangeException(paramName: nameof(end), message: "end must be a letter");
if (end <= start)
throw new ArgumentException($"{nameof(end)} must be greater than {nameof(start)}");
return AlphabetSubsetImplementation();
IEnumerable<char> AlphabetSubsetImplementation()
{
for(var c = start; c < end; c++)
yield return c;
}
}
Local functions
• Used for async methods:
• Without local function exception is thrown asynhronously as part of the awaitable
• With use of local function exceptions arising from argument validation are thrown before the asynchronous work
begins
public Task<string> PerformLongRunningWork(string address, int index, string name)
{
if(string.IsNullOrWhiteSpace(address))
throw new ArgumentException(message: "An address is required", paramName: nameof(address));
if (index < 0)
throw new ArgumentOutOfRangeException(paramName: nameof(index), message: "The index must be non-negative");
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException(message: "You must supply a name", paramName: nameof(name));
return LongRunningWorkImplementation();
async Task<string> LongRunningWorkImplementation()
{
var interimResult = await FirstWork(address);
var secondResult = await SecondStep(index, name);
return $"The results are {interimResult} and {secondResult}. Enjoy.";
}
}
Local functions compared to Lambda expressions
• For lambda expressions, the compiler must create an anonymous class and an instance of that class to store any
variables captured by the closure.
• Lambda expressions are implemented by instantiating a delegate (extra memory allocation) and invoking that
delegate.
• Lambda expressions must be declared before they are defined. This means local functions are easier to use in
recursive algorithms.
There are a number of reasons to prefer using local functions instead of defining and calling lambda expressions:
public static int LocalFunctionFactorial(int n)
{
return NthFactorial(n);
int NthFactorial(int number) => (number < 2) ? 1 : number * NthFactorial(number - 1);
}
public static int LambdaFactorial(int n)
{
Func<int, int> nthFactorial = default(Func<int, int>);
nthFactorial = (number) => (number < 2) ? 1 : number * nthFactorial(number - 1);
return nthFactorial(n);
}
More expression-bodied members
// Expression-bodied constructor
public ExpressionMembersExample(string label) => this.Label = label;
// Expression-bodied finalizer
~ExpressionMembersExample() => Console.Error.WriteLine("Finalized!");
private string label;
// Expression-bodied get / set accessors.
public string Label
{
get => label;
set => this.label = value ?? "Default label";
}
Throw expressions
string result = argument ?? throw new ArgumentNullException(nameof(argument));
string result = items.Length > 0 ? items[0] : throw new ArgumentException("items argument should have at least 1 element");
private string GetName() => throw new NotImplementedException();
Generalized async return types
• Methods declared with the async modifier can return other types in addition to Task,Task<T> and void
• Returning aTask object from async methods can introduce performance bottlenecks because of allocating memory for
Task which is a reference type.
• The returned type must still satisfy the async pattern, meaning a GetAwaiter method must be accessible.
• ValueTask type has been added to the .NET framework to make use of this new language feature. It can accept a result
orTask in constructor.
public ValueTask<int> CachedFunc()
{
return (cache) ? new ValueTask<int>(cacheResult) : new ValueTask<int>(LoadCache());
}
private bool cache = false;
private int cacheResult;
private async Task<int> LoadCache()
{
// simulate async work:
await Task.Delay(100);
cache = true;
cacheResult = 100;
return cacheResult;
}
Numeric literal syntax improvements
• The 0b at the beginning of the constant indicates that the number is written as a binary number.
• Binary numbers can get very long, so it's often easier to see the bit patterns by introducing the _ as a digit separator.
• The digit separator can appear anywhere in the constant. For base 10 numbers, it would be common to use it as a
thousands separator.
• The digit separator can be used with decimal, float and double types as well.
public const int One = 0b0001;
public const int Eight = 0b1000;
public const int Sixteen = 0b0001_0000;
public const int OneHundredTwentyEight = 0b1000_0000;
public const long BillionsAndBillions = 100_000_000_000;
public const double AvogadroConstant = 6.022_140_857_747_474e23;
public const decimal GoldenRatio = 1.618_033_988_749_894_848_204_586_834_365_638_117_720_309_179M;
Thank you

Contenu connexe

Tendances

Inline function
Inline functionInline function
Inline functionTech_MX
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6rohassanie
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language Mohamed Loey
 
Creating Lazy stream in CSharp
Creating Lazy stream in CSharpCreating Lazy stream in CSharp
Creating Lazy stream in CSharpDhaval Dalal
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.Russell Childs
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08HUST
 
What's new in Scala 2.13?
What's new in Scala 2.13?What's new in Scala 2.13?
What's new in Scala 2.13?Hermann Hueck
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programsharman kaur
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVAMuskanSony
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMMario Fusco
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16HUST
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays kinan keshkeh
 
The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185Mahmoud Samir Fayed
 

Tendances (20)

Inline function
Inline functionInline function
Inline function
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
C++ Programming Language
C++ Programming Language C++ Programming Language
C++ Programming Language
 
Creating Lazy stream in CSharp
Creating Lazy stream in CSharpCreating Lazy stream in CSharp
Creating Lazy stream in CSharp
 
C++11
C++11C++11
C++11
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
 
What's new in Scala 2.13?
What's new in Scala 2.13?What's new in Scala 2.13?
What's new in Scala 2.13?
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 
TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Pragmatic sbt
Pragmatic sbtPragmatic sbt
Pragmatic sbt
 
Csphtp1 16
Csphtp1 16Csphtp1 16
Csphtp1 16
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185
 

Similaire à What’s new in .NET

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
What's new in c# 8.0
What's new in c# 8.0What's new in c# 8.0
What's new in c# 8.0Moaid Hathot
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...Sang Don Kim
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5thConnex
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++Manzoor ALam
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6Andy Butland
 
Parallel and Async Programming With C#
Parallel and Async Programming With C#Parallel and Async Programming With C#
Parallel and Async Programming With C#Rainer Stropek
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008Luis Enrique
 
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
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#ANURAG SINGH
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScriptJungsoo Nam
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 

Similaire à What’s new in .NET (20)

What's new in C# 8.0 (beta)
What's new in C# 8.0 (beta)What's new in C# 8.0 (beta)
What's new in C# 8.0 (beta)
 
C
CC
C
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
What's new in c# 8.0
What's new in c# 8.0What's new in c# 8.0
What's new in c# 8.0
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
Presentation 5th
Presentation 5thPresentation 5th
Presentation 5th
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
 
Parallel and Async Programming With C#
Parallel and Async Programming With C#Parallel and Async Programming With C#
Parallel and Async Programming With C#
 
ASP.NET Basics
ASP.NET Basics ASP.NET Basics
ASP.NET Basics
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
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
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
Best practices tekx
Best practices tekxBest practices tekx
Best practices tekx
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Should i Go there
Should i Go thereShould i Go there
Should i Go there
 
Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScript
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 

Dernier

%+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
 
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
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
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
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
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
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%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
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
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
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
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
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 

Dernier (20)

%+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...
 
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
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
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
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
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...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%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
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
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...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
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
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

What’s new in .NET

  • 1. What’s new in .NET ADRIAN STANULA
  • 2. What's new in .NET Platform
  • 4. What is .NET Standard? • .NET Standard is a specification, not an implementation • .NET Standard provides a common base .NET Interface to all platforms that implement it so that no matter which version of .NET you use you'll always see at least the same base feature set. • .NET Standard describes what a specific implementation like .NET Core, Mono, Xamarin or .NET 4.6 has to implement - at minimum - in terms of API surface in order to be compliant with a given version of .NET Standard.
  • 5. .NET platforms support The following table lists all versions of .NET Standard and the platforms supported: • The higher the version, the more APIs are available to you.The lower the version, the more platforms implement it. • https://docs.microsoft.com/en-us/dotnet/api (see also https://apisof.net)
  • 6. What’s new in .NET Standard 2.0
  • 7. .NET Standard under the hood • When .NET Standard class library references .NET Framework library it uses special version of mscorlib.dll that translates types from .NET Framework to .NET Standard • Type forwarding is done for each .NET Framework assembly
  • 8. .NET Standard under the hood • When specific .NET runtime, e.g. .NET Core class library references .NET Standard library it uses special version of netstandard.dll that translates types from .NET Standard to .NET Core
  • 9. Migrating to .NET Standard • .NET Portability Analyzer – plugin toVisual Studio • https://github.com/Microsoft/dotnet-apiport
  • 10. What’s new in .NET Core? • .NET Core 1.1 released • Official release of .NET Core tools (with change in the tooling layers) • This shared SDK component is a set of MSBuild targets and associated tasks that are responsible for compiling your code, publishing it, packing NuGet packages etc. • Moving away from project.json to .csproj • CLI commands are translated to MSBuild invocations. • Visual Studio invokes MSBuild directly
  • 11. What’s new in Visual Studio 2017
  • 12. Performance improvements • A new setup experience • StartVisual Studio faster (The Performance Center lists all the extensions and tool windows that might slow down the IDE startup) • Decrease solution load time • Faster on-demand loading of extensions
  • 13. Productivity improvements • Manage your extensions with Roaming Extensions Manager • When you use the Roaming Extension Manager, you will notice 3 icon types on your list: Roamed, Roamed & Installed, Installed • Live architecture dependency validation • Live UnitTesting
  • 14. Visual Studio IDE enhancements • View and navigate code with StructureVisualizer • Experience improved navigation controls • GoTo (Ctrl+F12) – navigate from any base type or member to its various implementations. • GoTo All (Ctrl+T or Ctrl+,) – navigate directly to any file/type/member/symbol declaration.You can filter your result list or use the query syntax (for example, “f searchTerm” for files, “t searchTerm” for types, etc.). • Find All References (Shift+F12) – with syntax colorization, you can group FindAll Reference results by a combination of project, definition, and path.You can also “lock” results so that you can continue to find other references without losing your original results. • Indent Guides – dotted, gray vertical lines act as landmarks in code to provide context within your frame of view. • Live edit and reload of .csproj file
  • 15. Debugging and Diagnostics • Run to Click • New Exception Helper
  • 16. Docker Containers support • Develop, Run, Debug, Update your Web & Console Applications in a Docker Container • Multi-container debugging • Edit & Refresh of code • Publish to Azure App Service
  • 17. What’s new in C# 7.0
  • 18. New C# language features • More expression-bodied members • throw Expressions • Generalized async return types • Numeric literal syntax improvements • out variables • Tuples • Pattern Maching • ref locals and returns • Local Functions
  • 19. out variables int numericResult; if (!int.TryParse(input, out numericResult)) { return 0; } return numericResult; if (!int.TryParse(input, out var numericResult)) { return 0; } return numericResult; • Previously, you would need to separate the declaration of the out variable and its initialization into two different statements: • You can now declare out variables in the argument list of a method call, rather than writing a separate declaration statement: • The code is easier to read. • No need to assign an initial value. • Support for explicit type as well as var
  • 20. Tuples creation • Unnamed tuple: • Named tuple: • The new tuples features require the System.ValueTuple type. It can be referenced via NuGet. var unnamed = ("one", 10); Console.WriteLine(unnamed.Item1 + unnamed.Item2); var named = (First: "one", Second: 10); Console.WriteLine(named.First + named.Second); (string First, int Second) named = ("one", 10); Console.WriteLine(named.First + named.Second); (string First, int Second) named = (A: "one", B: 10); Console.WriteLine(named.First + unnamed.Second);
  • 21. Tuples as method return values • Methods can return tuple results: private (string First, int Second) GetResult() { string first = "one"; int second = 10; return (first, second); } private (string First, int Second) GetResult() { var result = (First: "one", Second: 10); return result; } var result = GetResult(); Console.WriteLine(result.First + result.Second); (double first, var second) = GetResult(); Console.WriteLine(first + second); private (string First, int Second) GetResult() { var result = new Tuple<string, int>("one", 10); return result; //THIS WILL NOT COMPILE } private (string First, int Second) GetResult() { var (first, second) = new Tuple<string, int>("one", 10); return (first, second); } • Method result can be assigned to single value or deconstructed:
  • 22. Tuples as method return values • Methods can return generic types with tuple: private IEnumerable<(string First, int Second)> GetResult() { yield return ("one", 10); } • As well as array of tuple values: IEnumerable<(string First, int Second)> result = GetResult(); IEnumerable<(string, int)> result2 = GetResult(); var result3 = GetResult(); private (string First, int Second)[] GetResult() { return new (string, int)[] {("one", 10)}; } (string First, int Second)[] result = GetResult(); (string, int)[] result2 = GetResult(); var result3 = GetResult();
  • 23. Tuples - deconstruction • Reconstructing a tuple: • Deconstructing user defined types: (string first, int second) = GetTupleResult(); var (first, second) = GetTupleResult(); public class Person { public string FirstName { get; } public string LastName { get; } public void Deconstruct(out string firstName, out string lastName) { firstName = FirstName; lastName = LastName; } } var p = new Person("Althea", "Goodwin"); var (first, last) = p; • Deconstructing using extension method: public static class PersonExtensions { public static void Deconstruct(this Person person, out string firstName, out string lastName) { firstName = person.FirstName; lastName = person.LastName; } }
  • 24. Pattern Matching if (shape is Square) { var s = shape as Square; return s.Side * s.Side; } • is operator: • Pattern matching switch statement : • The order of the case expressions now matters. • If you accidentally order match expressions such that a less explicit case has already been handled, the compiler will flag that and generate an error. • The default case is always evaluated last, regardless of the order it appears in the source. if (shape is Square s) { return s.Side * s.Side; } • The is type pattern expression: switch (shape) { case 0: return 0; case int val: return val^2; case Square s when s.Side == 0: case Triangle t when t.Base == 0 || t.Height == 0: return 0; case Square s: return s.Side * s.Side; case Triangle t: return t.Base * t.Height * 2; case null: throw new ArgumentNullException(nameof(shape)); default: throw new ArgumentException(nameof(shape)); }
  • 25. ref locals and returns public static ref int Find(int number, int[] numbers) { for (int i = 0; i < numbers.Length; i++) { if (numbers[i] == number) { return ref numbers[i]; // return the storage location, not the value //return numbers[i]; // this will not compile } } throw new InvalidOperationException("Not found"); } • Just like you can pass things by reference (with the ref modifier) in C#, you can now return them by reference, and also store them by reference in local variables. • You could only accomplish this by using unsafe code and returning a pointer to an int in previous versions. • When you declare that a method returns a ref variable, you must also add the ref keyword to each return statement. That indicates return by reference, and helps developers reading the code later remember that the method returns by reference. int[] array = { 1, 15, -39, 0, 7, 14, -12 }; ref int place = ref Find(7, array); // gets reference to 7's place in the array place = 9; // replaces 7 with 9 in the array Console.WriteLine(array[4]); // prints 9
  • 26. ref locals and returns var place = Find(7, array); // in this case 7 is printed • The variable place is an int, not a ref int.The var keyword enables the compiler to specify the type, but will not implicitly add the ref modifier. Instead, the value referred to by the ref return is copied to the variable on the left-hand side of the assignment. The variable is not a ref local. • You must initialize a ref variable when it is declared, you cannot split the declaration and the initialization. int place = Find(7, array); // in this case 7 is printed var place = ref Find(7, array); // this will not compile ref int place = Find(7, array); // this will not compile
  • 27. ref locals and returns • You cannot assign a value to a ref variable. That disallows statements like • You cannot return a ref to a variable whose lifetime does not extend beyond the execution of the method. That means you cannot return a reference to a local variable, or similar scope. ref int i = sequence.Count(); The C# language has two other rules that protect you from misusing the ref locals and returns: These rules ensure that you cannot accidentally mix value variables and reference variables. They also ensure that you cannot have a reference variable refer to storage that is a candidate for garbage collection.
  • 28. Local functions • Used in public iterator methods: • When checks and logic are in the same method exceptions are not thrown when method is invoked, but only when result is iterated (because it is iterator method) • When checks are in public method and logic in private then exceptions are thrown when the method is invoked (because it is no longer an iterator method), but programmer is able to invoke private method without checks • When logic is in local function then exception is thrown when method is invoked and programmer is not able to invoke logic from local function without checks public static IEnumerable<char> AlphabetSubset(char start, char end) { if ((start < 'a') || (start > 'z')) throw new ArgumentOutOfRangeException(paramName: nameof(start), message: "start must be a letter"); if ((end < 'a') || (end > 'z')) throw new ArgumentOutOfRangeException(paramName: nameof(end), message: "end must be a letter"); if (end <= start) throw new ArgumentException($"{nameof(end)} must be greater than {nameof(start)}"); return AlphabetSubsetImplementation(); IEnumerable<char> AlphabetSubsetImplementation() { for(var c = start; c < end; c++) yield return c; } }
  • 29. Local functions • Used for async methods: • Without local function exception is thrown asynhronously as part of the awaitable • With use of local function exceptions arising from argument validation are thrown before the asynchronous work begins public Task<string> PerformLongRunningWork(string address, int index, string name) { if(string.IsNullOrWhiteSpace(address)) throw new ArgumentException(message: "An address is required", paramName: nameof(address)); if (index < 0) throw new ArgumentOutOfRangeException(paramName: nameof(index), message: "The index must be non-negative"); if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException(message: "You must supply a name", paramName: nameof(name)); return LongRunningWorkImplementation(); async Task<string> LongRunningWorkImplementation() { var interimResult = await FirstWork(address); var secondResult = await SecondStep(index, name); return $"The results are {interimResult} and {secondResult}. Enjoy."; } }
  • 30. Local functions compared to Lambda expressions • For lambda expressions, the compiler must create an anonymous class and an instance of that class to store any variables captured by the closure. • Lambda expressions are implemented by instantiating a delegate (extra memory allocation) and invoking that delegate. • Lambda expressions must be declared before they are defined. This means local functions are easier to use in recursive algorithms. There are a number of reasons to prefer using local functions instead of defining and calling lambda expressions: public static int LocalFunctionFactorial(int n) { return NthFactorial(n); int NthFactorial(int number) => (number < 2) ? 1 : number * NthFactorial(number - 1); } public static int LambdaFactorial(int n) { Func<int, int> nthFactorial = default(Func<int, int>); nthFactorial = (number) => (number < 2) ? 1 : number * nthFactorial(number - 1); return nthFactorial(n); }
  • 31. More expression-bodied members // Expression-bodied constructor public ExpressionMembersExample(string label) => this.Label = label; // Expression-bodied finalizer ~ExpressionMembersExample() => Console.Error.WriteLine("Finalized!"); private string label; // Expression-bodied get / set accessors. public string Label { get => label; set => this.label = value ?? "Default label"; }
  • 32. Throw expressions string result = argument ?? throw new ArgumentNullException(nameof(argument)); string result = items.Length > 0 ? items[0] : throw new ArgumentException("items argument should have at least 1 element"); private string GetName() => throw new NotImplementedException();
  • 33. Generalized async return types • Methods declared with the async modifier can return other types in addition to Task,Task<T> and void • Returning aTask object from async methods can introduce performance bottlenecks because of allocating memory for Task which is a reference type. • The returned type must still satisfy the async pattern, meaning a GetAwaiter method must be accessible. • ValueTask type has been added to the .NET framework to make use of this new language feature. It can accept a result orTask in constructor. public ValueTask<int> CachedFunc() { return (cache) ? new ValueTask<int>(cacheResult) : new ValueTask<int>(LoadCache()); } private bool cache = false; private int cacheResult; private async Task<int> LoadCache() { // simulate async work: await Task.Delay(100); cache = true; cacheResult = 100; return cacheResult; }
  • 34. Numeric literal syntax improvements • The 0b at the beginning of the constant indicates that the number is written as a binary number. • Binary numbers can get very long, so it's often easier to see the bit patterns by introducing the _ as a digit separator. • The digit separator can appear anywhere in the constant. For base 10 numbers, it would be common to use it as a thousands separator. • The digit separator can be used with decimal, float and double types as well. public const int One = 0b0001; public const int Eight = 0b1000; public const int Sixteen = 0b0001_0000; public const int OneHundredTwentyEight = 0b1000_0000; public const long BillionsAndBillions = 100_000_000_000; public const double AvogadroConstant = 6.022_140_857_747_474e23; public const decimal GoldenRatio = 1.618_033_988_749_894_848_204_586_834_365_638_117_720_309_179M;