SlideShare a Scribd company logo
1 of 24
C# 6
Pascal Laurin
November 2015
@plaurin78
pascal.laurin@outlook.com
www.pascallaurin.com
http://fr.slideshare.net/PascalLaurin
https://bitbucket.org/pascallaurin
Microsoft .NET MVP
Developer & Architect at GSoft
A brief history of C#
What’s new in C# 6
C# vNext
Agenda
Created by a team lead by Anders Hejlsberg
Inspiration from Pascal and Delphi
Now working on TypeScript
C# 1: The beginning [2002]
Ref: https://en.wikipedia.org/wiki/Anders_Hejlsberg
Generics
Anonymous Methods
Nullable Type
Partial Class
Iterators
C# 2 : Generics [2005]
new Dictionary<int, string>();
delegate() { Console.WriteLine("Hello"); }
int? a = null;
if (a.HasValue) { }
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
public static IEnumerable<int> Generate()
{
foreach (var item in Enumerable.Repeat(5, 5))
yield return item * 2;
}
C# .NET Framework CLR Visual Studio
1 1.0 1.0 .NET
1 1.1 1.1 2003
2 2.0 2.0 2005
2 3.0 2.0 -
3 3.5 2.0 2008
4 4.0 4.0 2010
5 4.5 4.0 2012
- 4.5.1 4.0 2013
6 4.6 4.0 2015
Interlude :
C# vs .NET Framework vs CLR vs Visual
Studio
Ref: https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx
Implicit Type (var)
Object and Collection Initializers
Auto-Implemented Properties
Lambda Expression
C# 3 : LINQ [2008]
var result = data.Where(x => x % 2 == 0);
var data = new[] { 1, 2, 3 };
var entity = new Entity { Name = "Pascal" };
internal class Entity
{
public string Name { get; set; }
}
LINQ
Anonymous Types
Extension Method
Expression Tree
C# 3 : LINQ [2008]
A.CallTo(() => repository.GetEntityById(idEntity))
.Returns(fakeEntity);
var result = data.Select(x => new
{
Name = x.ToString(),
Value = x
});
public static class Enumerable
{
public static IEnumerable<TSource> Where<TSource>(
this IEnumerable<TSource> source,
Func<TSource, bool> predicate)
{
...
}
}
https://www.linqpad.net/
C# scratch pad
100+ samples on LINQ, F#, Async, RX
https://code.visualstudio.com/
Cross platform editor
http://csharppad.com/
Online editor
http://scriptcs.net/
C# scripting
http://pexforfun.com/
Mastermind game in C#
Interlude :
Editors and tools
Dynamic
Named Arguments
Optional Parameters
C# 4 : Dynamic [2010]
dynamic d = entity;
d.CallMethod("Foo");
entity.CallMethod(value: 42, name: "Pascal");
public void CallMethod(string name, int value = 0) { }
Async Feature
Caller Information
C# 5 : Async [2012]
private async Task Do()
{
var client = new HttpClient();
var result = await client.GetAsync("http://www.google.com");
}
public void CallMethod([CallerFilePath] string filePath = "Unknown",
[CallerMemberName] string memberName = "Unknown",
[CallerLineNumber] int line = -1)
{
}
What is a compiler?
Interlude :
What is Roslyn?
Code Compiler Executable
Compiler As A Service
Interlude :
What is Roslyn?
Expression-level features
Nameof
String interpolation
Null-conditional operators (Elvis operator)
Index initializers
Statement-level features
Exception filters
Await in catch and finally blocks
Member declaration features
Auto-properties initializers
Getter-only auto-properties
Expression-bodied function members
Import features
Using static
Demos!!
C# 6 : Developer productivity [2015]
Nameof
String interpolation
Expression-level features
var dog = new Dog();
Console.WriteLine(
$"My dog {dog.Name,10} is {dog.Age} year{(dog.Age > 1 ? "s" : "")} old");
public static class NameOf
{
public static void MyMethod(string message)
{
if (message == null) throw new ArgumentNullException(nameof(message));
Console.WriteLine(nameof(message));
Console.WriteLine(
nameof(MyApp.Namespace.Demos) + nameof(NameOf) + nameof(MyMethod));
const int foo = 42;
Console.WriteLine(nameof(foo));
}
Null-conditional operators (Elvis operator)
Index initializers
Expression-level features
order?.Items?.Count;
order?.Items?[0].Name;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
var j = new JObject
{
["firstName"] = "Pascal",
["lastName"] = "Laurin«
};
Exception filters
Await in catch and finally blocks
Statement-level features
catch (Exception e) when (e.Message == "Foo")
{
Console.WriteLine("Was Foo");
}
catch (Exception)
{
var catchResult = await client.GetAsync("http://www.catch.com");
Console.WriteLine($"Catch: {catchResult.StatusCode}");
}
finally
{
var finallyResult = await client.GetAsync("http://www.finally.com");
Console.WriteLine($"Finally: {finallyResult.StatusCode}");
}
Auto-properties initializers
Getter-only auto-properties
Expression-bodied function members
Member declaration features
public string First { get; private set; } = "Pascal";
public string Last { get; private set; } = "Laurin";
public string First { get; } = "Pascal";
public string Last { get; } = "Laurin";
public int SomeFct(int a, int b) => a * b + a;
public string GetFullName() => $"{First} {Last}";
public void Print() => Console.WriteLine(GetFullName());
public string this[long id] => (id * 2).ToString();
Xamarin Studio “Roslyn” Preview Release
https://developer.xamarin.com/guides/cross-platform/xamarin-
studio/
Interlude :
Mono and Xamarin?
Outline of C# 7 demo at MVP Summit 2015-11-02
https://github.com/dotnet/roslyn/issues/6505
C# 7 Work List of Features
https://github.com/dotnet/roslyn/issues/2136
Design Notes
https://github.com/dotnet/roslyn/labels/Design%20Notes
Area-Language Design
https://github.com/dotnet/roslyn/labels/Area-Language%20Design
C# 7 and beyond
21
Local functions
static void Main(string[] args)
{
int Fib(int n) => (n < 2) ? 1 : Fib(n - 1) + Fib(n - 2); //!
Console.WriteLine(Fib(7));
Console.ReadKey();
}
static void Main(string[] args)
{
int fib0 = 1; //!
int Fib(int n) => (n < 2) ? fib0 : Fib(n - 1) + Fib(n - 2);
Console.WriteLine(Fib(7));
Console.ReadKey();
}
22
Records
// class Person(string Name);
class Person
{
public Person(string name) { this.Name = name; }
public string Name { get; }
}
// class Student(string Name, double Gpa) : Person(Name);
class Student : Person
{
public Student(string name, double gpa) : base(name) { this.Gpa = gpa; }
public double Gpa { get; }
}
// class Teacher(string Name, string Subject) : Person(Name);
class Teacher : Person
{
public Teacher(string name, string subject) : base(name)
{
this.Subject = subject;
}
public string Subject { get; }
}
23
Patterns matching
static string PrintedForm(Person p)
{
if (p is Student s && s.Gpa > 3.5) //!
{
return $"Honor Student {s.Name} ({s.Gpa})";
}
else if (p is Student s)
{
return $"Student {s.Name} ({s.Gpa})";
}
else if (p is Teacher t)
{
return $"Teacher {t.Name} of {t.Subject}";
}
else
{
return $"Person {p.Name}";
}
}
24
match expression and when clause
return p match ( //!
case Student s when s.Gpa > 3.5 : //!
$"Honor Student {s.Name} ({s.Gpa})"
case Student { Name is "Poindexter" } : //!
"A Nerd"
case Student s :
$"Student {s.Name} ({s.Gpa})"
case Teacher t :
$"Teacher {t.Name} of {t.Subject}"
case null : //!
throw new ArgumentNullException(nameof(p))
case * : //!
$"Person {p.Name}"
);
Language Features in C# 6
https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-
C%23-6
7 minutes video on C# 6
https://channel9.msdn.com/Series/ConnectOn-Demand/211
Questions?
References
@plaurin78
pascal.laurin@outlook.com
www.pascallaurin.com
http://fr.slideshare.net/PascalLaurin
https://bitbucket.org/pascallaurin/csharp6-talk

More Related Content

What's hot

DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)Alvaro Sanchez-Mariscal
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomasintuit_india
 
Karate, the black belt of HTTP API testing?
Karate, the black belt of HTTP API testing?Karate, the black belt of HTTP API testing?
Karate, the black belt of HTTP API testing?Bertrand Delacretaz
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravelDerek Binkley
 
Story Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium FrameworkStory Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium FrameworkOleksiy Rezchykov
 
Test automation with cucumber jvm
Test automation with cucumber jvmTest automation with cucumber jvm
Test automation with cucumber jvmNibu Baby
 
Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...
Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...
Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...ESUG
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEGavin Pickin
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingRoman Liubun
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad WoodOrtus Solutions, Corp
 
Spring Testing Features
Spring Testing FeaturesSpring Testing Features
Spring Testing FeaturesGil Zilberfeld
 
Intro To React Native
Intro To React NativeIntro To React Native
Intro To React NativeFITC
 
Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5rtpaem
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativePolidea
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleVodqaBLR
 
Getting Started with React Native (and should I use it at all?)
Getting Started with React Native (and should I use it at all?)Getting Started with React Native (and should I use it at all?)
Getting Started with React Native (and should I use it at all?)Devin Abbott
 

What's hot (20)

DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
 
BDD for APIs
BDD for APIsBDD for APIs
BDD for APIs
 
Nativescript with angular 2
Nativescript with angular 2Nativescript with angular 2
Nativescript with angular 2
 
Karate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter ThomasKarate for Complex Web-Service API Testing by Peter Thomas
Karate for Complex Web-Service API Testing by Peter Thomas
 
Karate, the black belt of HTTP API testing?
Karate, the black belt of HTTP API testing?Karate, the black belt of HTTP API testing?
Karate, the black belt of HTTP API testing?
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
 
Story Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium FrameworkStory Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium Framework
 
Test automation with cucumber jvm
Test automation with cucumber jvmTest automation with cucumber jvm
Test automation with cucumber jvm
 
Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...
Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...
Towards Modularity in Live Visual Modeling: A case-study with OpenPonk and Ke...
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
 
BDD and Behave
BDD and BehaveBDD and Behave
BDD and Behave
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Wood
 
Why I am hooked on the future of React
Why I am hooked on the future of ReactWhy I am hooked on the future of React
Why I am hooked on the future of React
 
Spring Testing Features
Spring Testing FeaturesSpring Testing Features
Spring Testing Features
 
Intro To React Native
Intro To React NativeIntro To React Native
Intro To React Native
 
Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5Test Driven Development in AEM/CQ5
Test Driven Development in AEM/CQ5
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made Simple
 
Getting Started with React Native (and should I use it at all?)
Getting Started with React Native (and should I use it at all?)Getting Started with React Native (and should I use it at all?)
Getting Started with React Native (and should I use it at all?)
 

Viewers also liked

Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#Pascal Laurin
 
Behaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowBehaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowPascal Laurin
 
7 astuces pour améliorer vos tests unitaires
7 astuces pour améliorer vos tests unitaires7 astuces pour améliorer vos tests unitaires
7 astuces pour améliorer vos tests unitairesPascal Laurin
 
L'amélioration des tests unitaires par le refactoring
L'amélioration des tests unitaires par le refactoringL'amélioration des tests unitaires par le refactoring
L'amélioration des tests unitaires par le refactoringPascal Laurin
 
Tests automatisés java script
Tests automatisés java scriptTests automatisés java script
Tests automatisés java scriptPascal Laurin
 
Cloud design patterns
Cloud design patternsCloud design patterns
Cloud design patternsPascal Laurin
 
Project Lambda: Evolution of Java
Project Lambda: Evolution of JavaProject Lambda: Evolution of Java
Project Lambda: Evolution of JavaCan Pekdemir
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)Alan Dean
 
Domain Driven Design - garajco Education 2017
Domain Driven Design - garajco Education 2017Domain Driven Design - garajco Education 2017
Domain Driven Design - garajco Education 2017Can Pekdemir
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 

Viewers also liked (12)

Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
Behaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlowBehaviour Driven Development with SpecFlow
Behaviour Driven Development with SpecFlow
 
7 astuces pour améliorer vos tests unitaires
7 astuces pour améliorer vos tests unitaires7 astuces pour améliorer vos tests unitaires
7 astuces pour améliorer vos tests unitaires
 
L'amélioration des tests unitaires par le refactoring
L'amélioration des tests unitaires par le refactoringL'amélioration des tests unitaires par le refactoring
L'amélioration des tests unitaires par le refactoring
 
Tests automatisés java script
Tests automatisés java scriptTests automatisés java script
Tests automatisés java script
 
Cloud design patterns
Cloud design patternsCloud design patterns
Cloud design patterns
 
Project Lambda: Evolution of Java
Project Lambda: Evolution of JavaProject Lambda: Evolution of Java
Project Lambda: Evolution of Java
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)
 
Domain Driven Design - garajco Education 2017
Domain Driven Design - garajco Education 2017Domain Driven Design - garajco Education 2017
Domain Driven Design - garajco Education 2017
 
Starbucks Wait Time Analysis
Starbucks Wait Time AnalysisStarbucks Wait Time Analysis
Starbucks Wait Time Analysis
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 

Similar to C# 6 Features and Beyond

Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo FinochiettiRoslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti.NET Conf UY
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
C# and the Evolution of a Programming Language
C# and the Evolution of a Programming LanguageC# and the Evolution of a Programming Language
C# and the Evolution of a Programming LanguageJacinto Limjap
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Jimmy Schementi
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8tdc-globalcode
 
Roslyn and C# 6.0 New Features
Roslyn and C# 6.0 New FeaturesRoslyn and C# 6.0 New Features
Roslyn and C# 6.0 New FeaturesMichael Step
 
Mercury: A Functional Review
Mercury: A Functional ReviewMercury: A Functional Review
Mercury: A Functional ReviewMark Cheeseman
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Building a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGLBuilding a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGLLuka Jacobowitz
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?intelliyole
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Windows Developer
 
C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8Giovanni Bassi
 
.Net passé, présent et futur
.Net passé, présent et futur.Net passé, présent et futur
.Net passé, présent et futurDenis Voituron
 
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...BIWUG
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...Maarten Balliauw
 
What's coming in c# 9.0
What's coming in c# 9.0What's coming in c# 9.0
What's coming in c# 9.0Moaid Hathot
 

Similar to C# 6 Features and Beyond (20)

What's New in C# 6
What's New in C# 6What's New in C# 6
What's New in C# 6
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
 
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo FinochiettiRoslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
Roslyn: el futuro de C# y VB.NET by Rodolfo Finochietti
 
Roslyn: el futuro de C#
Roslyn: el futuro de C#Roslyn: el futuro de C#
Roslyn: el futuro de C#
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
C# and the Evolution of a Programming Language
C# and the Evolution of a Programming LanguageC# and the Evolution of a Programming Language
C# and the Evolution of a Programming Language
 
Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011Iron Languages - NYC CodeCamp 2/19/2011
Iron Languages - NYC CodeCamp 2/19/2011
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
 
Roslyn and C# 6.0 New Features
Roslyn and C# 6.0 New FeaturesRoslyn and C# 6.0 New Features
Roslyn and C# 6.0 New Features
 
Mercury: A Functional Review
Mercury: A Functional ReviewMercury: A Functional Review
Mercury: A Functional Review
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Building a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGLBuilding a Tagless Final DSL for WebGL
Building a Tagless Final DSL for WebGL
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
 
C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8
 
.Net passé, présent et futur
.Net passé, présent et futur.Net passé, présent et futur
.Net passé, présent et futur
 
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
 
What's coming in c# 9.0
What's coming in c# 9.0What's coming in c# 9.0
What's coming in c# 9.0
 

Recently uploaded

SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 

Recently uploaded (20)

SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 

C# 6 Features and Beyond

  • 1. C# 6 Pascal Laurin November 2015 @plaurin78 pascal.laurin@outlook.com www.pascallaurin.com http://fr.slideshare.net/PascalLaurin https://bitbucket.org/pascallaurin Microsoft .NET MVP Developer & Architect at GSoft
  • 2. A brief history of C# What’s new in C# 6 C# vNext Agenda
  • 3. Created by a team lead by Anders Hejlsberg Inspiration from Pascal and Delphi Now working on TypeScript C# 1: The beginning [2002] Ref: https://en.wikipedia.org/wiki/Anders_Hejlsberg
  • 4. Generics Anonymous Methods Nullable Type Partial Class Iterators C# 2 : Generics [2005] new Dictionary<int, string>(); delegate() { Console.WriteLine("Hello"); } int? a = null; if (a.HasValue) { } public partial class Form1 : Form { public Form1() { InitializeComponent(); } } public static IEnumerable<int> Generate() { foreach (var item in Enumerable.Repeat(5, 5)) yield return item * 2; }
  • 5. C# .NET Framework CLR Visual Studio 1 1.0 1.0 .NET 1 1.1 1.1 2003 2 2.0 2.0 2005 2 3.0 2.0 - 3 3.5 2.0 2008 4 4.0 4.0 2010 5 4.5 4.0 2012 - 4.5.1 4.0 2013 6 4.6 4.0 2015 Interlude : C# vs .NET Framework vs CLR vs Visual Studio Ref: https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx
  • 6. Implicit Type (var) Object and Collection Initializers Auto-Implemented Properties Lambda Expression C# 3 : LINQ [2008] var result = data.Where(x => x % 2 == 0); var data = new[] { 1, 2, 3 }; var entity = new Entity { Name = "Pascal" }; internal class Entity { public string Name { get; set; } }
  • 7. LINQ Anonymous Types Extension Method Expression Tree C# 3 : LINQ [2008] A.CallTo(() => repository.GetEntityById(idEntity)) .Returns(fakeEntity); var result = data.Select(x => new { Name = x.ToString(), Value = x }); public static class Enumerable { public static IEnumerable<TSource> Where<TSource>( this IEnumerable<TSource> source, Func<TSource, bool> predicate) { ... } }
  • 8. https://www.linqpad.net/ C# scratch pad 100+ samples on LINQ, F#, Async, RX https://code.visualstudio.com/ Cross platform editor http://csharppad.com/ Online editor http://scriptcs.net/ C# scripting http://pexforfun.com/ Mastermind game in C# Interlude : Editors and tools
  • 9. Dynamic Named Arguments Optional Parameters C# 4 : Dynamic [2010] dynamic d = entity; d.CallMethod("Foo"); entity.CallMethod(value: 42, name: "Pascal"); public void CallMethod(string name, int value = 0) { }
  • 10. Async Feature Caller Information C# 5 : Async [2012] private async Task Do() { var client = new HttpClient(); var result = await client.GetAsync("http://www.google.com"); } public void CallMethod([CallerFilePath] string filePath = "Unknown", [CallerMemberName] string memberName = "Unknown", [CallerLineNumber] int line = -1) { }
  • 11. What is a compiler? Interlude : What is Roslyn? Code Compiler Executable
  • 12. Compiler As A Service Interlude : What is Roslyn?
  • 13. Expression-level features Nameof String interpolation Null-conditional operators (Elvis operator) Index initializers Statement-level features Exception filters Await in catch and finally blocks Member declaration features Auto-properties initializers Getter-only auto-properties Expression-bodied function members Import features Using static Demos!! C# 6 : Developer productivity [2015]
  • 14. Nameof String interpolation Expression-level features var dog = new Dog(); Console.WriteLine( $"My dog {dog.Name,10} is {dog.Age} year{(dog.Age > 1 ? "s" : "")} old"); public static class NameOf { public static void MyMethod(string message) { if (message == null) throw new ArgumentNullException(nameof(message)); Console.WriteLine(nameof(message)); Console.WriteLine( nameof(MyApp.Namespace.Demos) + nameof(NameOf) + nameof(MyMethod)); const int foo = 42; Console.WriteLine(nameof(foo)); }
  • 15. Null-conditional operators (Elvis operator) Index initializers Expression-level features order?.Items?.Count; order?.Items?[0].Name; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); var j = new JObject { ["firstName"] = "Pascal", ["lastName"] = "Laurin« };
  • 16. Exception filters Await in catch and finally blocks Statement-level features catch (Exception e) when (e.Message == "Foo") { Console.WriteLine("Was Foo"); } catch (Exception) { var catchResult = await client.GetAsync("http://www.catch.com"); Console.WriteLine($"Catch: {catchResult.StatusCode}"); } finally { var finallyResult = await client.GetAsync("http://www.finally.com"); Console.WriteLine($"Finally: {finallyResult.StatusCode}"); }
  • 17. Auto-properties initializers Getter-only auto-properties Expression-bodied function members Member declaration features public string First { get; private set; } = "Pascal"; public string Last { get; private set; } = "Laurin"; public string First { get; } = "Pascal"; public string Last { get; } = "Laurin"; public int SomeFct(int a, int b) => a * b + a; public string GetFullName() => $"{First} {Last}"; public void Print() => Console.WriteLine(GetFullName()); public string this[long id] => (id * 2).ToString();
  • 18. Xamarin Studio “Roslyn” Preview Release https://developer.xamarin.com/guides/cross-platform/xamarin- studio/ Interlude : Mono and Xamarin?
  • 19. Outline of C# 7 demo at MVP Summit 2015-11-02 https://github.com/dotnet/roslyn/issues/6505 C# 7 Work List of Features https://github.com/dotnet/roslyn/issues/2136 Design Notes https://github.com/dotnet/roslyn/labels/Design%20Notes Area-Language Design https://github.com/dotnet/roslyn/labels/Area-Language%20Design C# 7 and beyond
  • 20. 21 Local functions static void Main(string[] args) { int Fib(int n) => (n < 2) ? 1 : Fib(n - 1) + Fib(n - 2); //! Console.WriteLine(Fib(7)); Console.ReadKey(); } static void Main(string[] args) { int fib0 = 1; //! int Fib(int n) => (n < 2) ? fib0 : Fib(n - 1) + Fib(n - 2); Console.WriteLine(Fib(7)); Console.ReadKey(); }
  • 21. 22 Records // class Person(string Name); class Person { public Person(string name) { this.Name = name; } public string Name { get; } } // class Student(string Name, double Gpa) : Person(Name); class Student : Person { public Student(string name, double gpa) : base(name) { this.Gpa = gpa; } public double Gpa { get; } } // class Teacher(string Name, string Subject) : Person(Name); class Teacher : Person { public Teacher(string name, string subject) : base(name) { this.Subject = subject; } public string Subject { get; } }
  • 22. 23 Patterns matching static string PrintedForm(Person p) { if (p is Student s && s.Gpa > 3.5) //! { return $"Honor Student {s.Name} ({s.Gpa})"; } else if (p is Student s) { return $"Student {s.Name} ({s.Gpa})"; } else if (p is Teacher t) { return $"Teacher {t.Name} of {t.Subject}"; } else { return $"Person {p.Name}"; } }
  • 23. 24 match expression and when clause return p match ( //! case Student s when s.Gpa > 3.5 : //! $"Honor Student {s.Name} ({s.Gpa})" case Student { Name is "Poindexter" } : //! "A Nerd" case Student s : $"Student {s.Name} ({s.Gpa})" case Teacher t : $"Teacher {t.Name} of {t.Subject}" case null : //! throw new ArgumentNullException(nameof(p)) case * : //! $"Person {p.Name}" );
  • 24. Language Features in C# 6 https://github.com/dotnet/roslyn/wiki/New-Language-Features-in- C%23-6 7 minutes video on C# 6 https://channel9.msdn.com/Series/ConnectOn-Demand/211 Questions? References @plaurin78 pascal.laurin@outlook.com www.pascallaurin.com http://fr.slideshare.net/PascalLaurin https://bitbucket.org/pascallaurin/csharp6-talk