SlideShare ist ein Scribd-Unternehmen logo
1 von 60
C# 7.0What?! C# is Being Updated?
Abhishek Sur, Microsoft MVP
Architect, Insync
Page
HistoryofC#
2
Page
C# 2.0
• Generics
• Partial types
• Anonymous methods
• Iterators
• Nullable types
• Getter/Setter separate accessibility
• Static classes
• And more..
3
Page
C# 3.0
• Implicitly typed local variables
• Object and collection initializers
• Auto-properties
• Anonymous types
• Extension methods
• Query expressions
• Lambda expressions
• Expression trees
• And more..
4
Page
C# 4.0
• Dynamic binding
• Named and optional parameters
• Generic co- and contravariance
• And more..
5
Page
C# 5.0
• Asynchronous methods using Async and Await
• Caller info attributes
6
Page
The state of the Compiler
• It’s been a black box
• Roslyn to the rescue!
• .NET Compiler Platform
• Microsoft decides to re-write the compiler
• Compiler written in C#
• Easier to extend and maintain
• Open Source!
7
Page
C# 6.0 Overview
• Auto-property initializers
• Getter-only auto-properties
• Assignment to getter-only auto-properties
from constructor
• Parameter-less struct constructors
• Using Statements for Static Members
• Dictionary Initializer
• Await in catch/finally
• Exception filters
• Expression-bodied members
/ Copyright ©2014 by Readify Pty Ltd 8
› Nullpropagation
› Stringinterpolation
› nameofoperator
› Andmore..
Page
Auto-Property
Initializers
9
Page
Auto-property initializers in a nutshell
10
class Person
{
public string Name { get; set; }
}
class Person
{
public string Name { get; } = "Anonymous";
}
= "Anonymous";
Page
Auto-property initializers in a nutshell
11
class Person
{
public string Name { get; }
public Person()
{
Name = “Abhishek";
}
}
Page
Auto-property initializers in a nutshell
/ Copyright ©2014 by Readify Pty Ltd 12
class Person
{
private readonly string <Name>k__BackingField = “Abhishek";
public string Name
{
get
{
return this.<Name>k__BackingField;
}
}
}
Page
Parameter-less
structconstructors
13
Page
Parameter-less struct constructors in a nutshell
/ Copyright ©2014 by Readify Pty Ltd 14
@fekberg
struct Point
{
public int X { get; }
public int Y { get; }
}
Read Only!
public Point()
{
X = 100;
Y = 100;
}
Page
Parameter-less struct constructors in a nutshell
15
Read Only!
struct Point
{
private readonly int <X>k__BackingField;
private readonly int <Y>k__BackingField;
public int X
{
get
{
return this.<X>k__BackingField;
}
}
public int Y
{
get
{
return this.<Y>k__BackingField;
}
}
public Point()
{
this.<X>k__BackingField = 100;
this.<Y>k__BackingField = 100;
}
}
Page
Parameter-less struct constructors in a nutshell
16
Read Only!
struct Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y)
{
X = x;
Y = y;
}
public Point() : this(100, 100)
{
}
}
Page
UsingStatements
forStatic
Members
17
Page
Using Statements for Static Members in a nutshell
18
class Program
{
static void Main(string[] args)
{
var angle = 90d;
Console.WriteLine(Math.Sin(angle));
}
}
Page
Using Statements for Static Members in a nutshell
19
using System.Console;
using System.Math;
class Program
{
static void Main(string[] args)
{
var angle = 90d;
WriteLine(Sin(angle));
}
}
Page
Using Statements for Static Members in a nutshell
20
using System.Console;
using System.Linq.Enumerable;
class Program
{
static void Main(string[] args)
{
foreach (var i in Range(0, 10))
{
WriteLine(i);
}
}
}
Page
Dictionary
Initializers
Page
Dictionary Initializers in a nutshell
22
var people = new Dictionary<string, Person>
{
[“abhishek"] = new Person()
};
var answers = new Dictionary<int, string>
{
[42] = "the answer to life the universe and everything"
};
Page
Awaitinside
Finallyblock
Page
Await + Finally in a nutshell
24
public async Task DownloadAsync()
{
}
try
{ }
catch
{
await Task.Delay(2000);
}
finally
{
await Task.Delay(2000);
}
Page
ExceptionFilters
Page
Exception filters in a nutshell
26
try
{
throw new CustomException { Severity = 100 };
}
catch (CustomException ex) if (ex.Severity > 50)
{
Console.WriteLine("*BING BING* WARNING *BING BING*");
}
catch (CustomException ex)
{
Console.WriteLine("Whooops!");
}
Page
NullPropagation
Page
Null propagation in a nutshell
28
class Person
{
public string Name { get; set; }
public Address Address { get; set; }
}
Console.WriteLine(abhishek.Address.AddressLine1);
var abhishe = new Person
{
Name = “Abhishek"
};
class Address
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
}
Page
Null propagation in a nutshell
29
class Person
{
public string Name { get; set; }
public Address Address { get; set; }
}
Console.WriteLine(abhishek.Address.AddressLine1);
var abhishek = new Person
{
Name = “abhishek"
};
class Address
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
}
Page
Null propagation in a nutshell
30
class Person
{
public string Name { get; set; }
public Address Address { get; set; }
}
Console.WriteLine(abhishek.Address.AddressLine1);Console.WriteLine(abhishek.Address == null ? "No Address" : abhishek.Address.AddressLine1);
var abhishek = new Person
{
Name = “abhishek"
};
class Address
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
}
Page
Null propagation in a nutshell
31
class Person
{
public string Name { get; set; }
public Address Address { get; set; }
}
Console.WriteLine(ahishek.Address.AddressLine1);Console.WriteLine(abhishek.Address == null ? "No Address" : abhishek.Address.AddressLine1);
Console.WriteLine(abhishek?.Address?.AddressLine1 ?? "No Address");
var abhishek = new Person
{
Name = “abhishek"
};
class Address
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
}
Page
Null propagation in a nutshell
32
@fekberg
var people = new[]
{
new Person(),
null
};
WriteLine(people[0]?.Name);
WriteLine(people[1]?.Name);
Page
Null propagation in a nutshell
33
Person[] people = null;
WriteLine(people?[0]?.Name);
Person[] people = null;
Console.WriteLine(
(people != null) ?
((people[0] == null) ? null : people[0].Name)
: null
);
Page
Expression-bodied
members
Page
Expression-bodied members in a nutshell
35
class Rectangle
{
public double Width { get; set; }
public double Height { get; set; }
public double Area => Width * Height;
}
Page
Expression-bodied members in a nutshell
36
class Rectangle
{
public double Width { get; set; }
public double Height { get; set; }
public override string ToString() =>
"My Width is {Width} and my Height is {Height}";
}
Page
String
interpolation
Page
String interpolation in a nutshell
38
public override string ToString() =>
"My Width is {Width} and my Height is {Height}";
public override string ToString() =>
$"My Width is {Width} and my Height is {Height}";
Syntax will change in a later release to the following:
Page
String interpolation in a nutshell
39
public override string ToString() =>
"My Width is {Width} and my Height is {Height}";
public override string ToString()
{
object[] args = new object[] { this.Width, this.Height };
return string.Format("My Width is {0} and my Height is {1}", args);
}
Page
String interpolation in a nutshell
40
int age = 28;
var result = "Hello there, I'm {age : D5} years old!";
WriteLine(result);
int num = 28;
object[] objArray1 = new object[] { num };
Console.WriteLine(string.Format("Hello there, I'm {0:D5} years old!", objArray1));
Page
nameof
operator
Page
nameof operator in a nutshell
42
static void Main(string[] args)
{
WriteLine("Parameter name is: {nameof(args)}");
}
Page
nameof operator in a nutshell
43
public double CalculateArea(int width, int height)
{
if (width <= 0)
{
throw new ArgumentException("Parameter {nameof(width)} cannot be less than 0");
}
return width * height;
}
Page
There’smore??
C#7.0
44
Page
How to try?
45
• InstallVisual Studio Preview 2 and create project with experimental
compilation symbol.
Page
What about C# 7.0?
• Binary literals and Digit separators
46
0b00001000
0xFF_00_FA_AF
Page
What about C# 7.0?
• Event initializers
47
var client = new WebClient
{
DownloadFileCompleted +=
DownloadFileCompletedHandler
};
Page
What about C# 7.0?
• Nested Methods
48
Void MyMethod(){
void calculator(int x)
{
return x * 2;
};
return calculator(10);
}
Page
What about C# 7.0?
• Field targets on auto-properties
49
[field: NonSerialized]
public int Age { get; set; }
Page
What about C# 7.0?
• Inherent use ofTuples and language integration
50
(int x, int y) MyFunction(){
Console.WriteLine(“My Tuple is called”);
}
Page
What about C# 7.0?
Inherent use ofTuples and language integration
51
public class Person
{
public readonly (string firstName, string lastName) Names; // a tuple
public Person((string FirstName, string LastName)) names, int Age)
{
Names = names;
}
}
Page
What about C# 7.0?
Inherent use ofTuples and language integration
52
(string first, string last) = GetNames("Inigo Montoya")
Page
What about C# 7.0?
• Using params with IEnumerable
53
int Avg(params IEnumerable<int> numbers)
Page
What about C# 7.0?
• Declaration Expressions
54
public void CalculateAgeBasedOn(int birthYear, out int age)
{
age = DateTime.Now.Year - birthYear;
}
CalculateAgeBasedOn(1987, out var age);
Page
What about C# 7.0?
• Primary Constructors
55
class Person(string name, int age)
{
private string _name = name;
private int _age = age;
}
Page
What about C# 7.0?
• Pattern Matching
56
object obj;
// ...
switch(obj) {
case 42:
// ...
case Color.Red:
// ...
case string s:
// ...
case Point(int x, 42) where (Y > 42):
// ...
case Point(490, 42): // fine
// ...
default:
// ...
}
Page
What about C# 7.0?
• Async Streams
• IAsyncEnumerable will also work withAwait. It has MoveNextAsync and Current
property like IEnumerable, and you can call them using foreach loops.
57
Page
What about C# 7.0?
• Immutable Objects
• Inherently thread-safe
• Makes it easier to use and reason about code
• Easier to parallelize your code
• Reference to immutable objects can be cached, as they won’t change
58
public immutable class Point
{
public Point(int x, int y)
{
x = x;
Y = y;
}
public int X { get; }
public int Y { get; }
}
Page
Summary
• C# 6.0 is awesome
• There’s a lot of change in C# 6.0
• .NET Compiler Platform ("Roslyn") makes it easy for Microsoft
to improve the language
• There’s a lot of interesting features that could go in C# 7.0
60
Page
Questions?
61

Weitere ähnliche Inhalte

Was ist angesagt?

Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Chris Richardson
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8Christian Nagel
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей КоваленкоFwdays
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongMario Fusco
 
Expression trees in C#
Expression trees in C#Expression trees in C#
Expression trees in C#Oleksii Holub
 
Oleksii Holub "Expression trees in C#"
Oleksii Holub "Expression trees in C#" Oleksii Holub "Expression trees in C#"
Oleksii Holub "Expression trees in C#" Fwdays
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better JavaGarth Gilmour
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mark Needham
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!Boy Baukema
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)David de Boer
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme SwiftMovel
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2José Paumard
 
Java 8 Streams & Collectors : the Leuven edition
Java 8 Streams & Collectors : the Leuven editionJava 8 Streams & Collectors : the Leuven edition
Java 8 Streams & Collectors : the Leuven editionJosé Paumard
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickHermann Hueck
 

Was ist angesagt? (20)

Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...Map(), flatmap() and reduce() are your new best friends: simpler collections,...
Map(), flatmap() and reduce() are your new best friends: simpler collections,...
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
Expression trees in C#
Expression trees in C#Expression trees in C#
Expression trees in C#
 
Sneaking inside Kotlin features
Sneaking inside Kotlin featuresSneaking inside Kotlin features
Sneaking inside Kotlin features
 
Oleksii Holub "Expression trees in C#"
Oleksii Holub "Expression trees in C#" Oleksii Holub "Expression trees in C#"
Oleksii Holub "Expression trees in C#"
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Writing Parsers and Compilers with PLY
Writing Parsers and Compilers with PLYWriting Parsers and Compilers with PLY
Writing Parsers and Compilers with PLY
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Java 8 Streams & Collectors : the Leuven edition
Java 8 Streams & Collectors : the Leuven editionJava 8 Streams & Collectors : the Leuven edition
Java 8 Streams & Collectors : the Leuven edition
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with Slick
 

Andere mochten auch

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
 
C# 6.0 - What?! C# is being updated?
C# 6.0 - What?! C# is being updated?C# 6.0 - What?! C# is being updated?
C# 6.0 - What?! C# is being updated?Filip Ekberg
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6Amir Barylko
 
5 Hidden Performance Problems for ASP.NET
5 Hidden Performance Problems for ASP.NET5 Hidden Performance Problems for ASP.NET
5 Hidden Performance Problems for ASP.NETMatt Watson
 
The Little Wonders of C# 6
The Little Wonders of C# 6The Little Wonders of C# 6
The Little Wonders of C# 6BlackRabbitCoder
 
Donetconf2016: The Future of C#
Donetconf2016: The Future of C#Donetconf2016: The Future of C#
Donetconf2016: The Future of C#Jacinto Limjap
 
Python for the C# developer
Python for the C# developerPython for the C# developer
Python for the C# developerMichael Kennedy
 
C# features through examples
C# features through examplesC# features through examples
C# features through examplesZayen Chagra
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegantalenttransform
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsAniruddha Chakrabarti
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introductionPeter Gfader
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial Jm Ramos
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core ConceptsFabio Biondi
 
10 Tips for Making Beautiful Slideshow Presentations by www.visuali.se
10 Tips for Making Beautiful Slideshow Presentations by www.visuali.se10 Tips for Making Beautiful Slideshow Presentations by www.visuali.se
10 Tips for Making Beautiful Slideshow Presentations by www.visuali.seEdahn Small
 

Andere mochten auch (16)

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
 
C# 6.0 - What?! C# is being updated?
C# 6.0 - What?! C# is being updated?C# 6.0 - What?! C# is being updated?
C# 6.0 - What?! C# is being updated?
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
5 Hidden Performance Problems for ASP.NET
5 Hidden Performance Problems for ASP.NET5 Hidden Performance Problems for ASP.NET
5 Hidden Performance Problems for ASP.NET
 
The Little Wonders of C# 6
The Little Wonders of C# 6The Little Wonders of C# 6
The Little Wonders of C# 6
 
Donetconf2016: The Future of C#
Donetconf2016: The Future of C#Donetconf2016: The Future of C#
Donetconf2016: The Future of C#
 
Python for the C# developer
Python for the C# developerPython for the C# developer
Python for the C# developer
 
Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
C# features through examples
C# features through examplesC# features through examples
C# features through examples
 
Evolution of c# - by K.Jegan
Evolution of c# - by K.JeganEvolution of c# - by K.Jegan
Evolution of c# - by K.Jegan
 
Future of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows Platforms
 
.NET and C# introduction
.NET and C# introduction.NET and C# introduction
.NET and C# introduction
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core Concepts
 
10 Tips for Making Beautiful Slideshow Presentations by www.visuali.se
10 Tips for Making Beautiful Slideshow Presentations by www.visuali.se10 Tips for Making Beautiful Slideshow Presentations by www.visuali.se
10 Tips for Making Beautiful Slideshow Presentations by www.visuali.se
 
C# 7
C# 7C# 7
C# 7
 

Ähnlich wie C# 7.0 Hacks and Features

C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsMohammad Shaker
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptHendrik Ebbers
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Tudor Dragan
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»SpbDotNet Community
 
Writing good code
Writing good codeWriting good code
Writing good codeIshti Gupta
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020Joseph Kuo
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvmArnaud Giuliani
 
Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Fwdays
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNikolas Burk
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.pptpsundarau
 
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
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir DresherTamir Dresher
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядомAndrey Akinshin
 

Ähnlich wie C# 7.0 Hacks and Features (20)

C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and Objects
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScript
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
 
Oops concept
Oops conceptOops concept
Oops concept
 
Writing good code
Writing good codeWriting good code
Writing good code
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
OOP Core Concept
OOP Core ConceptOOP Core Concept
OOP Core Concept
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"Nikita Galkin "Looking for the right tech stack for GraphQL application"
Nikita Galkin "Looking for the right tech stack for GraphQL application"
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and Prisma
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.ppt
 
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
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
C++ theory
C++ theoryC++ theory
C++ theory
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
 

Mehr von Abhishek Sur

Azure servicefabric
Azure servicefabricAzure servicefabric
Azure servicefabricAbhishek Sur
 
Building a bot with an intent
Building a bot with an intentBuilding a bot with an intent
Building a bot with an intentAbhishek Sur
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to conceptsAbhishek Sur
 
Stream Analytics Service in Azure
Stream Analytics Service in AzureStream Analytics Service in Azure
Stream Analytics Service in AzureAbhishek Sur
 
Designing azure compute and storage infrastructure
Designing azure compute and storage infrastructureDesigning azure compute and storage infrastructure
Designing azure compute and storage infrastructureAbhishek Sur
 
Working with Azure Resource Manager Templates
Working with Azure Resource Manager TemplatesWorking with Azure Resource Manager Templates
Working with Azure Resource Manager TemplatesAbhishek Sur
 
F12 debugging in Ms edge
F12 debugging in Ms edgeF12 debugging in Ms edge
F12 debugging in Ms edgeAbhishek Sur
 
Mobile Services for Windows Azure
Mobile Services for Windows AzureMobile Services for Windows Azure
Mobile Services for Windows AzureAbhishek Sur
 
Service bus to build Bridges
Service bus to build BridgesService bus to build Bridges
Service bus to build BridgesAbhishek Sur
 
Windows azure pack overview
Windows azure pack overviewWindows azure pack overview
Windows azure pack overviewAbhishek Sur
 
AMicrosoft azure hyper v recovery manager overview
AMicrosoft azure hyper v recovery manager overviewAMicrosoft azure hyper v recovery manager overview
AMicrosoft azure hyper v recovery manager overviewAbhishek Sur
 
Di api di server b1 ws
Di api di server b1 wsDi api di server b1 ws
Di api di server b1 wsAbhishek Sur
 
Integrating cortana with wp8 app
Integrating cortana with wp8 appIntegrating cortana with wp8 app
Integrating cortana with wp8 appAbhishek Sur
 
Asp.net performance
Asp.net performanceAsp.net performance
Asp.net performanceAbhishek Sur
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its featuresAbhishek Sur
 
SQL Server2012 Enhancements
SQL Server2012 EnhancementsSQL Server2012 Enhancements
SQL Server2012 EnhancementsAbhishek Sur
 
Dev days Visual Studio 2012 Enhancements
Dev days Visual Studio 2012 EnhancementsDev days Visual Studio 2012 Enhancements
Dev days Visual Studio 2012 EnhancementsAbhishek Sur
 
Hidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsHidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsAbhishek Sur
 
ASP.NET 4.5 webforms
ASP.NET 4.5 webformsASP.NET 4.5 webforms
ASP.NET 4.5 webformsAbhishek Sur
 

Mehr von Abhishek Sur (20)

Azure servicefabric
Azure servicefabricAzure servicefabric
Azure servicefabric
 
Building a bot with an intent
Building a bot with an intentBuilding a bot with an intent
Building a bot with an intent
 
Code review
Code reviewCode review
Code review
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
Stream Analytics Service in Azure
Stream Analytics Service in AzureStream Analytics Service in Azure
Stream Analytics Service in Azure
 
Designing azure compute and storage infrastructure
Designing azure compute and storage infrastructureDesigning azure compute and storage infrastructure
Designing azure compute and storage infrastructure
 
Working with Azure Resource Manager Templates
Working with Azure Resource Manager TemplatesWorking with Azure Resource Manager Templates
Working with Azure Resource Manager Templates
 
F12 debugging in Ms edge
F12 debugging in Ms edgeF12 debugging in Ms edge
F12 debugging in Ms edge
 
Mobile Services for Windows Azure
Mobile Services for Windows AzureMobile Services for Windows Azure
Mobile Services for Windows Azure
 
Service bus to build Bridges
Service bus to build BridgesService bus to build Bridges
Service bus to build Bridges
 
Windows azure pack overview
Windows azure pack overviewWindows azure pack overview
Windows azure pack overview
 
AMicrosoft azure hyper v recovery manager overview
AMicrosoft azure hyper v recovery manager overviewAMicrosoft azure hyper v recovery manager overview
AMicrosoft azure hyper v recovery manager overview
 
Di api di server b1 ws
Di api di server b1 wsDi api di server b1 ws
Di api di server b1 ws
 
Integrating cortana with wp8 app
Integrating cortana with wp8 appIntegrating cortana with wp8 app
Integrating cortana with wp8 app
 
Asp.net performance
Asp.net performanceAsp.net performance
Asp.net performance
 
Introduction to XAML and its features
Introduction to XAML and its featuresIntroduction to XAML and its features
Introduction to XAML and its features
 
SQL Server2012 Enhancements
SQL Server2012 EnhancementsSQL Server2012 Enhancements
SQL Server2012 Enhancements
 
Dev days Visual Studio 2012 Enhancements
Dev days Visual Studio 2012 EnhancementsDev days Visual Studio 2012 Enhancements
Dev days Visual Studio 2012 Enhancements
 
Hidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsHidden Facts of .NET Language Gems
Hidden Facts of .NET Language Gems
 
ASP.NET 4.5 webforms
ASP.NET 4.5 webformsASP.NET 4.5 webforms
ASP.NET 4.5 webforms
 

Kürzlich hochgeladen

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Kürzlich hochgeladen (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

C# 7.0 Hacks and Features

  • 1. C# 7.0What?! C# is Being Updated? Abhishek Sur, Microsoft MVP Architect, Insync
  • 3. Page C# 2.0 • Generics • Partial types • Anonymous methods • Iterators • Nullable types • Getter/Setter separate accessibility • Static classes • And more.. 3
  • 4. Page C# 3.0 • Implicitly typed local variables • Object and collection initializers • Auto-properties • Anonymous types • Extension methods • Query expressions • Lambda expressions • Expression trees • And more.. 4
  • 5. Page C# 4.0 • Dynamic binding • Named and optional parameters • Generic co- and contravariance • And more.. 5
  • 6. Page C# 5.0 • Asynchronous methods using Async and Await • Caller info attributes 6
  • 7. Page The state of the Compiler • It’s been a black box • Roslyn to the rescue! • .NET Compiler Platform • Microsoft decides to re-write the compiler • Compiler written in C# • Easier to extend and maintain • Open Source! 7
  • 8. Page C# 6.0 Overview • Auto-property initializers • Getter-only auto-properties • Assignment to getter-only auto-properties from constructor • Parameter-less struct constructors • Using Statements for Static Members • Dictionary Initializer • Await in catch/finally • Exception filters • Expression-bodied members / Copyright ©2014 by Readify Pty Ltd 8 › Nullpropagation › Stringinterpolation › nameofoperator › Andmore..
  • 10. Page Auto-property initializers in a nutshell 10 class Person { public string Name { get; set; } } class Person { public string Name { get; } = "Anonymous"; } = "Anonymous";
  • 11. Page Auto-property initializers in a nutshell 11 class Person { public string Name { get; } public Person() { Name = “Abhishek"; } }
  • 12. Page Auto-property initializers in a nutshell / Copyright ©2014 by Readify Pty Ltd 12 class Person { private readonly string <Name>k__BackingField = “Abhishek"; public string Name { get { return this.<Name>k__BackingField; } } }
  • 14. Page Parameter-less struct constructors in a nutshell / Copyright ©2014 by Readify Pty Ltd 14 @fekberg struct Point { public int X { get; } public int Y { get; } } Read Only! public Point() { X = 100; Y = 100; }
  • 15. Page Parameter-less struct constructors in a nutshell 15 Read Only! struct Point { private readonly int <X>k__BackingField; private readonly int <Y>k__BackingField; public int X { get { return this.<X>k__BackingField; } } public int Y { get { return this.<Y>k__BackingField; } } public Point() { this.<X>k__BackingField = 100; this.<Y>k__BackingField = 100; } }
  • 16. Page Parameter-less struct constructors in a nutshell 16 Read Only! struct Point { public int X { get; } public int Y { get; } public Point(int x, int y) { X = x; Y = y; } public Point() : this(100, 100) { } }
  • 18. Page Using Statements for Static Members in a nutshell 18 class Program { static void Main(string[] args) { var angle = 90d; Console.WriteLine(Math.Sin(angle)); } }
  • 19. Page Using Statements for Static Members in a nutshell 19 using System.Console; using System.Math; class Program { static void Main(string[] args) { var angle = 90d; WriteLine(Sin(angle)); } }
  • 20. Page Using Statements for Static Members in a nutshell 20 using System.Console; using System.Linq.Enumerable; class Program { static void Main(string[] args) { foreach (var i in Range(0, 10)) { WriteLine(i); } } }
  • 22. Page Dictionary Initializers in a nutshell 22 var people = new Dictionary<string, Person> { [“abhishek"] = new Person() }; var answers = new Dictionary<int, string> { [42] = "the answer to life the universe and everything" };
  • 24. Page Await + Finally in a nutshell 24 public async Task DownloadAsync() { } try { } catch { await Task.Delay(2000); } finally { await Task.Delay(2000); }
  • 26. Page Exception filters in a nutshell 26 try { throw new CustomException { Severity = 100 }; } catch (CustomException ex) if (ex.Severity > 50) { Console.WriteLine("*BING BING* WARNING *BING BING*"); } catch (CustomException ex) { Console.WriteLine("Whooops!"); }
  • 28. Page Null propagation in a nutshell 28 class Person { public string Name { get; set; } public Address Address { get; set; } } Console.WriteLine(abhishek.Address.AddressLine1); var abhishe = new Person { Name = “Abhishek" }; class Address { public string AddressLine1 { get; set; } public string AddressLine2 { get; set; } }
  • 29. Page Null propagation in a nutshell 29 class Person { public string Name { get; set; } public Address Address { get; set; } } Console.WriteLine(abhishek.Address.AddressLine1); var abhishek = new Person { Name = “abhishek" }; class Address { public string AddressLine1 { get; set; } public string AddressLine2 { get; set; } }
  • 30. Page Null propagation in a nutshell 30 class Person { public string Name { get; set; } public Address Address { get; set; } } Console.WriteLine(abhishek.Address.AddressLine1);Console.WriteLine(abhishek.Address == null ? "No Address" : abhishek.Address.AddressLine1); var abhishek = new Person { Name = “abhishek" }; class Address { public string AddressLine1 { get; set; } public string AddressLine2 { get; set; } }
  • 31. Page Null propagation in a nutshell 31 class Person { public string Name { get; set; } public Address Address { get; set; } } Console.WriteLine(ahishek.Address.AddressLine1);Console.WriteLine(abhishek.Address == null ? "No Address" : abhishek.Address.AddressLine1); Console.WriteLine(abhishek?.Address?.AddressLine1 ?? "No Address"); var abhishek = new Person { Name = “abhishek" }; class Address { public string AddressLine1 { get; set; } public string AddressLine2 { get; set; } }
  • 32. Page Null propagation in a nutshell 32 @fekberg var people = new[] { new Person(), null }; WriteLine(people[0]?.Name); WriteLine(people[1]?.Name);
  • 33. Page Null propagation in a nutshell 33 Person[] people = null; WriteLine(people?[0]?.Name); Person[] people = null; Console.WriteLine( (people != null) ? ((people[0] == null) ? null : people[0].Name) : null );
  • 35. Page Expression-bodied members in a nutshell 35 class Rectangle { public double Width { get; set; } public double Height { get; set; } public double Area => Width * Height; }
  • 36. Page Expression-bodied members in a nutshell 36 class Rectangle { public double Width { get; set; } public double Height { get; set; } public override string ToString() => "My Width is {Width} and my Height is {Height}"; }
  • 38. Page String interpolation in a nutshell 38 public override string ToString() => "My Width is {Width} and my Height is {Height}"; public override string ToString() => $"My Width is {Width} and my Height is {Height}"; Syntax will change in a later release to the following:
  • 39. Page String interpolation in a nutshell 39 public override string ToString() => "My Width is {Width} and my Height is {Height}"; public override string ToString() { object[] args = new object[] { this.Width, this.Height }; return string.Format("My Width is {0} and my Height is {1}", args); }
  • 40. Page String interpolation in a nutshell 40 int age = 28; var result = "Hello there, I'm {age : D5} years old!"; WriteLine(result); int num = 28; object[] objArray1 = new object[] { num }; Console.WriteLine(string.Format("Hello there, I'm {0:D5} years old!", objArray1));
  • 42. Page nameof operator in a nutshell 42 static void Main(string[] args) { WriteLine("Parameter name is: {nameof(args)}"); }
  • 43. Page nameof operator in a nutshell 43 public double CalculateArea(int width, int height) { if (width <= 0) { throw new ArgumentException("Parameter {nameof(width)} cannot be less than 0"); } return width * height; }
  • 45. Page How to try? 45 • InstallVisual Studio Preview 2 and create project with experimental compilation symbol.
  • 46. Page What about C# 7.0? • Binary literals and Digit separators 46 0b00001000 0xFF_00_FA_AF
  • 47. Page What about C# 7.0? • Event initializers 47 var client = new WebClient { DownloadFileCompleted += DownloadFileCompletedHandler };
  • 48. Page What about C# 7.0? • Nested Methods 48 Void MyMethod(){ void calculator(int x) { return x * 2; }; return calculator(10); }
  • 49. Page What about C# 7.0? • Field targets on auto-properties 49 [field: NonSerialized] public int Age { get; set; }
  • 50. Page What about C# 7.0? • Inherent use ofTuples and language integration 50 (int x, int y) MyFunction(){ Console.WriteLine(“My Tuple is called”); }
  • 51. Page What about C# 7.0? Inherent use ofTuples and language integration 51 public class Person { public readonly (string firstName, string lastName) Names; // a tuple public Person((string FirstName, string LastName)) names, int Age) { Names = names; } }
  • 52. Page What about C# 7.0? Inherent use ofTuples and language integration 52 (string first, string last) = GetNames("Inigo Montoya")
  • 53. Page What about C# 7.0? • Using params with IEnumerable 53 int Avg(params IEnumerable<int> numbers)
  • 54. Page What about C# 7.0? • Declaration Expressions 54 public void CalculateAgeBasedOn(int birthYear, out int age) { age = DateTime.Now.Year - birthYear; } CalculateAgeBasedOn(1987, out var age);
  • 55. Page What about C# 7.0? • Primary Constructors 55 class Person(string name, int age) { private string _name = name; private int _age = age; }
  • 56. Page What about C# 7.0? • Pattern Matching 56 object obj; // ... switch(obj) { case 42: // ... case Color.Red: // ... case string s: // ... case Point(int x, 42) where (Y > 42): // ... case Point(490, 42): // fine // ... default: // ... }
  • 57. Page What about C# 7.0? • Async Streams • IAsyncEnumerable will also work withAwait. It has MoveNextAsync and Current property like IEnumerable, and you can call them using foreach loops. 57
  • 58. Page What about C# 7.0? • Immutable Objects • Inherently thread-safe • Makes it easier to use and reason about code • Easier to parallelize your code • Reference to immutable objects can be cached, as they won’t change 58 public immutable class Point { public Point(int x, int y) { x = x; Y = y; } public int X { get; } public int Y { get; } }
  • 59. Page Summary • C# 6.0 is awesome • There’s a lot of change in C# 6.0 • .NET Compiler Platform ("Roslyn") makes it easy for Microsoft to improve the language • There’s a lot of interesting features that could go in C# 7.0 60