SlideShare a Scribd company logo
1 of 13
C# 6
One of the popular languages c-sharp has evolved over the years, under the guidance of
Anders_Hejlsberg, into a feature rich language that is used on billions of devices world-wide.
Version 6, is the first to be compiled with Roslyn the new compiler as a service. This is
important because unlike in previous versions, that were compiled with C++.
Roslyn is actually part of the .Net ecosystem. This will allow everybody to leverage the
compiler and ensure Microsoft can innovate C# at a faster cadence, while at the same time
ensuring more robust grammar parsing.
Null-conditional operators
This has to be the most important new feature and is designed to strengthen defensive
programming. By simply allowing you to write your code naturally while at the same time
providing null checking.
int? length = (users!= null)?users.Length:null;
This can now be re-written as.
int? length = users?.Length;
As you can imagine if require multiple levels of null checking, the code quickly becomes
unreadable.
string postCode = ((user != null) && (user.Address != null))
? user.Address.PostCode : null;
Is now far more succinct.
string postCode = user?.Address?.PostCode
Additional we can perform a null check against a delegate.
if (OnPropertyChanged != null)
{
OnPropertyChanged(this, value);
}
To this.
OnPropertyChanged?(this, value);
Await in catch and finally
The Async operator introduced in C# 5 didn't allow for the await keyword use in catch and finally
blocks. Which only forced the developer to implement workarounds to compensate. Now with C# 6
we have this feature and the last hurdle to Async programming has been removed.
Service service = new Service();
try
{
res = await service.OpenAsync(…); // We only had this.
}
catch(Exception e)
{
await LogService.LogAsync(service, e); // We Now have this.
}
finally
{
if (res != null) await service.CloseAsync(); // … and this.
}
nameof
Refactoring is good programming and Visual Studio includes refactoring tools, like renaming,
this works looking at parse the code to look too understand how to update the code. However,
consider the following:
public string SomeMethod(string valueOne, int valueTwo)
{
if (valueOne == null)
{
Throw new ArgumentException("the parameter valueOne of SomeMethod
is null");
}
If we now try to rename the SomeMethod or valueOne, visual studio would simple ignore
the message found in the argument exception, leaving this code stale.
However, with the nameof expression, we can rewrite this code to protect against rename
and event validate against spelling errors.
public string SomeMethod(string valueOne, int valueTwo)
{
if (valueOne == null)
{
throw new ArgumentException($"the parameter {nameof(valueOne)}
of {nameof(SomeMethod)} is null");
}
Some tools like Resharper do attempt to fix these issue they are not perfect.
String interpolation
String.Format is versatile and is preferable to concatenation, but it is little clunky and error prone. In
particular the placeholders {0} must match the arguments supplied separately or an exception is
thrown:
var s = string.format("{0,20} is {1:D3} years old", user.Name, user.Age);
Now becomes.
var s = $"{user.Name,20} is {user.Age:D3} years old";
Whats more you can also not included method call and and even extensions methods.
var s = $"{user.FullName()} is {DisplayAge(user)}";
This will produced more concise, readable and error less prone code.
Auto-Property Initializers
Properties have been in C# since the very beginning with a minor tweak. With version 6 we
can now initialize properties with an expression, so this.
public class Custom
{
public DateTime TimeStamp { get; private set; }
public Address address { get; private set; }
public Customer(string first, string last)
{
TimeStamp = DateTime.UtcNow;
Address = new Address();
Address .AddressLineOne=”197 Home Street”;
Address .PostCode = ”XX1 1SS”;
}
}
Becomes this.
public class Customer
{
public DateTime TimeStamp { get; } = DateTime.UtcNow;
public Address address { get; } = new Address {
AddressLineOne=”197 Home Street”,
PostCode = ”XX1 1SS”
};
}
using static
Previously if you wanted to access static methods you needed to prefix the contain class
which lead to more verbose code
using System;
class Program
{
static void Main()
{
Console.WriteLine(Math.Sqrt(3*3 + 4*4));
Console.WriteLine(DayOfWeek.Friday - DayOfWeek.Monday);
}
}
Now with the static using we can reduce this repetitive code too this.
using static System.Console;
using static System.Math;
using static System.DayOfWeek;
class Program
{
static void Main()
{
WriteLine(Sqrt(3*3 + 4*4));
WriteLine(Friday - Monday);
}
}
Like many of the other feature this improves readability, however the possibility namespace
clashes also increases.
Index Collection Initializers
We also have a small improvement to initializers, that allow us to explicitly declare that we're
setting an index, so this.
var numbers = new Dictionary<int, string> {
{7, "seven"},
{9 , "nine"},
{13 , "thirteen"}};
Becomes this.
var dict = new Dictionary<string, string> {
[7] = "seven" ,
[9] = "nine",
[13] = "thirteen" };
Now while if example above show that we're actually setting an index property, this feature
really shines with objects rather than values.
var customers = new Dictionary<string, Customer> {
["1"] = new Customer("joe","doe"),
["2"] = new Customer("joe","doe")
};
Under the covers all c# is doing is rewriting use the Add methods.
This boilerplate code while not necessary does increase the readability. I addition, C# will
can now resolve extension methods with will be able to allow any collection utilize Initialize rs.
Conclusion
You could be forgiven for thinking Microsoft is running out of idea's and the new feature are
only boiler plate code and that C# is starting to fossilize. While It's true that as programming
language mature, innovating is harder, as the grammar becomes more complex.
The process of migrating a language compiler onto a new platform is a huge undertaking. So
in future release we can expect more innovation to return. Finally, while these feature could
be described as boilerplate I would counter that this is true for high level languages as they
ultimately compile down to Assembly.

More Related Content

What's hot

C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...Codemotion
 
Actor Model pattern for concurrency
Actor Model pattern for concurrencyActor Model pattern for concurrency
Actor Model pattern for concurrencyggarber
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
Function overloading in c++
Function overloading in c++Function overloading in c++
Function overloading in c++Learn By Watch
 
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc ConceptsPython Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc ConceptsP3 InfoTech Solutions Pvt. Ltd.
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_unitskinan keshkeh
 
Building Services With gRPC, Docker and Go
Building Services With gRPC, Docker and GoBuilding Services With gRPC, Docker and Go
Building Services With gRPC, Docker and GoMartin Kess
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive CocoaSmartLogic
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherColin Eberhardt
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++ Bharat Kalia
 

What's hot (20)

C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...How much performance can you get out of Javascript? - Massimiliano Mantione -...
How much performance can you get out of Javascript? - Massimiliano Mantione -...
 
Actor Model pattern for concurrency
Actor Model pattern for concurrencyActor Model pattern for concurrency
Actor Model pattern for concurrency
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
 
Cocoa heads 09112017
Cocoa heads 09112017Cocoa heads 09112017
Cocoa heads 09112017
 
Objective c intro (1)
Objective c intro (1)Objective c intro (1)
Objective c intro (1)
 
The low level awesomeness of Go
The low level awesomeness of GoThe low level awesomeness of Go
The low level awesomeness of Go
 
Compile time polymorphism
Compile time polymorphismCompile time polymorphism
Compile time polymorphism
 
Function overloading in c++
Function overloading in c++Function overloading in c++
Function overloading in c++
 
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc ConceptsPython Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
 
Building Services With gRPC, Docker and Go
Building Services With gRPC, Docker and GoBuilding Services With gRPC, Docker and Go
Building Services With gRPC, Docker and Go
 
An Introduction to Reactive Cocoa
An Introduction to Reactive CocoaAn Introduction to Reactive Cocoa
An Introduction to Reactive Cocoa
 
ReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better TogetherReactiveCocoa and Swift, Better Together
ReactiveCocoa and Swift, Better Together
 
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M31 - PEP 8Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M31 - PEP 8
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Streams
StreamsStreams
Streams
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 

Viewers also liked

Resolucion problemas quinto
Resolucion problemas quintoResolucion problemas quinto
Resolucion problemas quintojustevez
 
05 la place de l'eglise
05 la place de l'eglise05 la place de l'eglise
05 la place de l'egliseSalle212
 
Os consumidores e o que os interessa
Os consumidores e o que os interessaOs consumidores e o que os interessa
Os consumidores e o que os interessadeiacosta
 
Calidad en salud
Calidad en saludCalidad en salud
Calidad en saludSusana Soto
 
Uso de las TIC en la educación del Siglo XXI
Uso de las TIC en la educación del Siglo XXIUso de las TIC en la educación del Siglo XXI
Uso de las TIC en la educación del Siglo XXIErick Miranda
 
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with RealmChristian Melchior
 
introduction to computer: Lec 1 orientation
introduction to computer: Lec 1 orientationintroduction to computer: Lec 1 orientation
introduction to computer: Lec 1 orientationProtik Roy
 
MapR-DB – The First In-Hadoop Document Database
MapR-DB – The First In-Hadoop Document DatabaseMapR-DB – The First In-Hadoop Document Database
MapR-DB – The First In-Hadoop Document DatabaseMapR Technologies
 
D3 in Jupyter : PyData NYC 2015
D3 in Jupyter : PyData NYC 2015D3 in Jupyter : PyData NYC 2015
D3 in Jupyter : PyData NYC 2015Brian Coffey
 
Anatomía dental y oclusión / 1er unidad / 1era clase: Características general...
Anatomía dental y oclusión / 1er unidad / 1era clase: Características general...Anatomía dental y oclusión / 1er unidad / 1era clase: Características general...
Anatomía dental y oclusión / 1er unidad / 1era clase: Características general...Christian Buleje
 

Viewers also liked (17)

Resolucion problemas quinto
Resolucion problemas quintoResolucion problemas quinto
Resolucion problemas quinto
 
05 la place de l'eglise
05 la place de l'eglise05 la place de l'eglise
05 la place de l'eglise
 
Zach Weil_Resume
Zach Weil_ResumeZach Weil_Resume
Zach Weil_Resume
 
Espectro
EspectroEspectro
Espectro
 
Os consumidores e o que os interessa
Os consumidores e o que os interessaOs consumidores e o que os interessa
Os consumidores e o que os interessa
 
Fire fox 2
Fire fox  2Fire fox  2
Fire fox 2
 
Ubi
UbiUbi
Ubi
 
Calidad en salud
Calidad en saludCalidad en salud
Calidad en salud
 
Uso de las TIC en la educación del Siglo XXI
Uso de las TIC en la educación del Siglo XXIUso de las TIC en la educación del Siglo XXI
Uso de las TIC en la educación del Siglo XXI
 
Painless Persistence with Realm
Painless Persistence with RealmPainless Persistence with Realm
Painless Persistence with Realm
 
introduction to computer: Lec 1 orientation
introduction to computer: Lec 1 orientationintroduction to computer: Lec 1 orientation
introduction to computer: Lec 1 orientation
 
Recurso de amparo habeas data
Recurso de amparo   habeas dataRecurso de amparo   habeas data
Recurso de amparo habeas data
 
4 εποχες – 4 χορδες
4 εποχες – 4 χορδες4 εποχες – 4 χορδες
4 εποχες – 4 χορδες
 
MapR-DB – The First In-Hadoop Document Database
MapR-DB – The First In-Hadoop Document DatabaseMapR-DB – The First In-Hadoop Document Database
MapR-DB – The First In-Hadoop Document Database
 
D3 in Jupyter : PyData NYC 2015
D3 in Jupyter : PyData NYC 2015D3 in Jupyter : PyData NYC 2015
D3 in Jupyter : PyData NYC 2015
 
Anatomía dental y oclusión / 1er unidad / 1era clase: Características general...
Anatomía dental y oclusión / 1er unidad / 1era clase: Características general...Anatomía dental y oclusión / 1er unidad / 1era clase: Características general...
Anatomía dental y oclusión / 1er unidad / 1era clase: Características general...
 
Arbeitsmarktbericht_Statistik März 2010.pdf
Arbeitsmarktbericht_Statistik März 2010.pdfArbeitsmarktbericht_Statistik März 2010.pdf
Arbeitsmarktbericht_Statistik März 2010.pdf
 

Similar to C# 6.0

The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project AnalyzedPVS-Studio
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6Nitay Neeman
 
An Introduction to TypeScript
An Introduction to TypeScriptAn Introduction to TypeScript
An Introduction to TypeScriptWrapPixel
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
why c++11?
why c++11?why c++11?
why c++11?idrajeev
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?PVS-Studio
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008Luis Enrique
 
Swift 5.2 what are the new things that you need to know about
Swift 5.2   what are the new things that you need to know aboutSwift 5.2   what are the new things that you need to know about
Swift 5.2 what are the new things that you need to know aboutConcetto Labs
 
PVS-Studio vs Chromium
PVS-Studio vs ChromiumPVS-Studio vs Chromium
PVS-Studio vs ChromiumPVS-Studio
 
PVS-Studio vs Chromium
PVS-Studio vs ChromiumPVS-Studio vs Chromium
PVS-Studio vs ChromiumAndrey Karpov
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Andrey Karpov
 

Similar to C# 6.0 (20)

The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project Analyzed
 
Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
An Introduction to TypeScript
An Introduction to TypeScriptAn Introduction to TypeScript
An Introduction to TypeScript
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
why c++11?
why c++11?why c++11?
why c++11?
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?Of complicacy of programming, or won't C# save us?
Of complicacy of programming, or won't C# save us?
 
New features in C# 6
New features in C# 6New features in C# 6
New features in C# 6
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Amusing C#
Amusing C#Amusing C#
Amusing C#
 
C#.net evolution part 2
C#.net evolution part 2C#.net evolution part 2
C#.net evolution part 2
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
 
Swift 5.2 what are the new things that you need to know about
Swift 5.2   what are the new things that you need to know aboutSwift 5.2   what are the new things that you need to know about
Swift 5.2 what are the new things that you need to know about
 
PVS-Studio vs Chromium
PVS-Studio vs ChromiumPVS-Studio vs Chromium
PVS-Studio vs Chromium
 
PVS-Studio vs Chromium
PVS-Studio vs ChromiumPVS-Studio vs Chromium
PVS-Studio vs Chromium
 
Oct.22nd.Presentation.Final
Oct.22nd.Presentation.FinalOct.22nd.Presentation.Final
Oct.22nd.Presentation.Final
 
Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...Consequences of using the Copy-Paste method in C++ programming and how to dea...
Consequences of using the Copy-Paste method in C++ programming and how to dea...
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
 
Ractive js
Ractive jsRactive js
Ractive js
 
Java lab 2
Java lab 2Java lab 2
Java lab 2
 

More from Paul Graham

Publising a nuget package
Publising a nuget packagePublising a nuget package
Publising a nuget packagePaul Graham
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generationPaul Graham
 
A guide to EPiServer CMS Scheduled Job
A guide to EPiServer CMS Scheduled JobA guide to EPiServer CMS Scheduled Job
A guide to EPiServer CMS Scheduled JobPaul Graham
 
Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServerPaul Graham
 
Adding disqus to ghost blog
Adding disqus to ghost blogAdding disqus to ghost blog
Adding disqus to ghost blogPaul Graham
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage ReportsPaul Graham
 
Entity framework (EF) 7
Entity framework (EF) 7Entity framework (EF) 7
Entity framework (EF) 7Paul Graham
 
Code syntax highlighting in ghost
Code syntax highlighting in ghostCode syntax highlighting in ghost
Code syntax highlighting in ghostPaul Graham
 

More from Paul Graham (8)

Publising a nuget package
Publising a nuget packagePublising a nuget package
Publising a nuget package
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generation
 
A guide to EPiServer CMS Scheduled Job
A guide to EPiServer CMS Scheduled JobA guide to EPiServer CMS Scheduled Job
A guide to EPiServer CMS Scheduled Job
 
Creating an nuget package for EPiServer
Creating an nuget package for EPiServerCreating an nuget package for EPiServer
Creating an nuget package for EPiServer
 
Adding disqus to ghost blog
Adding disqus to ghost blogAdding disqus to ghost blog
Adding disqus to ghost blog
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage Reports
 
Entity framework (EF) 7
Entity framework (EF) 7Entity framework (EF) 7
Entity framework (EF) 7
 
Code syntax highlighting in ghost
Code syntax highlighting in ghostCode syntax highlighting in ghost
Code syntax highlighting in ghost
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

C# 6.0

  • 1. C# 6 One of the popular languages c-sharp has evolved over the years, under the guidance of Anders_Hejlsberg, into a feature rich language that is used on billions of devices world-wide. Version 6, is the first to be compiled with Roslyn the new compiler as a service. This is important because unlike in previous versions, that were compiled with C++.
  • 2. Roslyn is actually part of the .Net ecosystem. This will allow everybody to leverage the compiler and ensure Microsoft can innovate C# at a faster cadence, while at the same time ensuring more robust grammar parsing. Null-conditional operators This has to be the most important new feature and is designed to strengthen defensive programming. By simply allowing you to write your code naturally while at the same time providing null checking. int? length = (users!= null)?users.Length:null; This can now be re-written as. int? length = users?.Length; As you can imagine if require multiple levels of null checking, the code quickly becomes unreadable. string postCode = ((user != null) && (user.Address != null))
  • 3. ? user.Address.PostCode : null; Is now far more succinct. string postCode = user?.Address?.PostCode Additional we can perform a null check against a delegate. if (OnPropertyChanged != null) { OnPropertyChanged(this, value); } To this. OnPropertyChanged?(this, value);
  • 4. Await in catch and finally The Async operator introduced in C# 5 didn't allow for the await keyword use in catch and finally blocks. Which only forced the developer to implement workarounds to compensate. Now with C# 6 we have this feature and the last hurdle to Async programming has been removed. Service service = new Service(); try { res = await service.OpenAsync(…); // We only had this. } catch(Exception e) { await LogService.LogAsync(service, e); // We Now have this. } finally { if (res != null) await service.CloseAsync(); // … and this. }
  • 5. nameof Refactoring is good programming and Visual Studio includes refactoring tools, like renaming, this works looking at parse the code to look too understand how to update the code. However, consider the following: public string SomeMethod(string valueOne, int valueTwo) { if (valueOne == null) { Throw new ArgumentException("the parameter valueOne of SomeMethod is null"); } If we now try to rename the SomeMethod or valueOne, visual studio would simple ignore the message found in the argument exception, leaving this code stale. However, with the nameof expression, we can rewrite this code to protect against rename and event validate against spelling errors.
  • 6. public string SomeMethod(string valueOne, int valueTwo) { if (valueOne == null) { throw new ArgumentException($"the parameter {nameof(valueOne)} of {nameof(SomeMethod)} is null"); } Some tools like Resharper do attempt to fix these issue they are not perfect.
  • 7. String interpolation String.Format is versatile and is preferable to concatenation, but it is little clunky and error prone. In particular the placeholders {0} must match the arguments supplied separately or an exception is thrown: var s = string.format("{0,20} is {1:D3} years old", user.Name, user.Age); Now becomes. var s = $"{user.Name,20} is {user.Age:D3} years old"; Whats more you can also not included method call and and even extensions methods. var s = $"{user.FullName()} is {DisplayAge(user)}"; This will produced more concise, readable and error less prone code.
  • 8. Auto-Property Initializers Properties have been in C# since the very beginning with a minor tweak. With version 6 we can now initialize properties with an expression, so this. public class Custom { public DateTime TimeStamp { get; private set; } public Address address { get; private set; } public Customer(string first, string last) { TimeStamp = DateTime.UtcNow; Address = new Address(); Address .AddressLineOne=”197 Home Street”; Address .PostCode = ”XX1 1SS”; } }
  • 9. Becomes this. public class Customer { public DateTime TimeStamp { get; } = DateTime.UtcNow; public Address address { get; } = new Address { AddressLineOne=”197 Home Street”, PostCode = ”XX1 1SS” }; }
  • 10. using static Previously if you wanted to access static methods you needed to prefix the contain class which lead to more verbose code using System; class Program { static void Main() { Console.WriteLine(Math.Sqrt(3*3 + 4*4)); Console.WriteLine(DayOfWeek.Friday - DayOfWeek.Monday); } }
  • 11. Now with the static using we can reduce this repetitive code too this. using static System.Console; using static System.Math; using static System.DayOfWeek; class Program { static void Main() { WriteLine(Sqrt(3*3 + 4*4)); WriteLine(Friday - Monday); } } Like many of the other feature this improves readability, however the possibility namespace clashes also increases.
  • 12. Index Collection Initializers We also have a small improvement to initializers, that allow us to explicitly declare that we're setting an index, so this. var numbers = new Dictionary<int, string> { {7, "seven"}, {9 , "nine"}, {13 , "thirteen"}}; Becomes this. var dict = new Dictionary<string, string> { [7] = "seven" , [9] = "nine", [13] = "thirteen" };
  • 13. Now while if example above show that we're actually setting an index property, this feature really shines with objects rather than values. var customers = new Dictionary<string, Customer> { ["1"] = new Customer("joe","doe"), ["2"] = new Customer("joe","doe") }; Under the covers all c# is doing is rewriting use the Add methods. This boilerplate code while not necessary does increase the readability. I addition, C# will can now resolve extension methods with will be able to allow any collection utilize Initialize rs. Conclusion You could be forgiven for thinking Microsoft is running out of idea's and the new feature are only boiler plate code and that C# is starting to fossilize. While It's true that as programming language mature, innovating is harder, as the grammar becomes more complex. The process of migrating a language compiler onto a new platform is a huge undertaking. So in future release we can expect more innovation to return. Finally, while these feature could be described as boilerplate I would counter that this is true for high level languages as they ultimately compile down to Assembly.