les nouveautés de c# 6
TRANSCRIPT
![Page 1: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/1.jpg)
#mstechdays techdays.microsoft.fr
![Page 2: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/2.jpg)
Agenda
• Introduction: evolution of C#• C# 6.0
• Getter-only auto-properties• Initializers for auto-properties• Using static classes• String interpolation• Expression-bodied methods• Expression-bodied properties• Index initializers• Null-conditional operator• Nameof operator• Exception filter
• Q&A
![Page 3: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/3.jpg)
The Evolution of C#
C# 1.0
C# 2.0
C# 3.0
Managed Code
Generics
Language Integrated Query
C# 4.0Dynamic Programming
C# 5.0Asynchrony (await)
![Page 4: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/4.jpg)
.Net Compiler Platform: Roslyn
•INTRODUCTION•EXPOSING THE COMPILER APIS
• COMPILER PIPELINE FUNCTIONAL AREAS• API LAYERS
• Compiler APIs• Workspaces APIs
•WORKING WITH SYNTAX• SYNTAX TREES• SYNTAX NODES• SYNTAX TOKENS• SYNTAX TRIVIA• SPANS• KINDS• ERRORS
•WORKING WITH SEMANTICS• COMPILATION• SYMBOLS• SEMANTIC MODEL
•WORKING WITH A WORKSPACE• WORKSPACE• SOLUTIONS, PROJECTS, DOCUMENTS
•SUMMARY
![Page 5: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/5.jpg)
Getter-only auto-properties
public class Point
{
public int X { get; set; }
public int Y { get; set; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
![Page 6: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/6.jpg)
Getter-only auto-properties
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
![Page 7: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/7.jpg)
Getter-only auto-properties
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
![Page 8: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/8.jpg)
Initializers for auto-properties
public class Point
{
public int X { get; } = 5;
public int Y { get; } = 7;
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
![Page 9: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/9.jpg)
Using static classesusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
![Page 10: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/10.jpg)
Using static classesusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Math.Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
![Page 11: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/11.jpg)
Using static classesusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
![Page 12: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/12.jpg)
String interpolationusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return String.Format("({0}, {1})", X, Y);
}
}
![Page 13: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/13.jpg)
String interpolationusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return "(\{X}, \{Y})";
}
}
![Page 14: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/14.jpg)
Expression-bodied methodsusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return "(\{X}, \{Y})";
}
}
![Page 15: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/15.jpg)
Expression-bodied methodsusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Sqrt(X * X + Y * Y); }
}
public override string ToString()
{
return "(\{X}, \{Y})";
}
}
() => { return "(\{X}, \{Y})"; }
() => "(\{X}, \{Y})"
![Page 16: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/16.jpg)
Expression-bodied methodsusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Sqrt(X * X + Y * Y); }
}
public override string ToString() => "(\{X}, \{Y})";
}
![Page 17: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/17.jpg)
Expression-bodied propertiesusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist
{
get { return Sqrt(X * X + Y * Y); }
}
public override string ToString() => "(\{X}, \{Y})";
}
![Page 18: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/18.jpg)
Expression-bodied propertiesusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist => Sqrt(X * X + Y * Y);
public override string ToString() => "(\{X}, \{Y})";
}
![Page 19: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/19.jpg)
Expression-bodied propertiesusing System.Math;
public class Point
{
public int X { get; }
public int Y { get; }
public Point(int x, int y) { X = x; Y = y; }
public double Dist => Sqrt(X * X + Y * Y);
public override string ToString() => "(\{X}, \{Y})";
}
![Page 20: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/20.jpg)
Index initializerspublic class Point
{
public int X { get; }
public int Y { get; }
…
public JObject ToJson()
{
var result = new JObject();
result["x"] = X;
result["y"] = Y;
return result;
}
}
![Page 21: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/21.jpg)
Index initializerspublic class Point
{
public int X { get; }
public int Y { get; }
…
public JObject ToJson()
{
var result = new JObject() { ["x"] = X, ["y"] = Y };
return result;
}}
![Page 22: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/22.jpg)
Index initializerspublic class Point
{
public int X { get; }
public int Y { get; }
…
public JObject ToJson()
{
return new JObject() { ["x"] = X, ["y"] = Y };
}
}
![Page 23: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/23.jpg)
Index initializerspublic class Point
{
public int X { get; }
public int Y { get; }
…
public JObject ToJson() =>
new JObject() { ["x"] = X, ["y"] = Y };
}
![Page 24: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/24.jpg)
Null-conditional operatorspublic static Point FromJson(JObject json)
{
if (json != null &&
json["x"] != null &&
json["x"].Type == JTokenType.Integer &&
json["y"] != null &&
json["y"].Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
![Page 25: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/25.jpg)
Null-conditional operatorspublic static Point FromJson(JObject json)
{
if (json != null &&
json["x"]?.Type == JTokenType.Integer &&
json["y"]?.Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
![Page 26: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/26.jpg)
Null-conditional operatorspublic static Point FromJson(JObject json)
{
if (json != null &&
json["x"]?.Type == JTokenType.Integer &&
json["y"]?.Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
?.
![Page 27: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/27.jpg)
Null-conditional operatorspublic static Point FromJson(JObject json)
{
if (json != null &&
json["x"]?.Type == JTokenType.Integer &&
json["y"]?.Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
![Page 28: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/28.jpg)
Null-conditional operatorspublic static Point FromJson(JObject json)
{
if (json?["x"]?.Type == JTokenType.Integer &&
json?["y"]?.Type == JTokenType.Integer)
{
return new Point((int)json["x"], (int)json["y"]);
}
return null;
}
![Page 29: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/29.jpg)
Null-conditional operators
OnChanged(this, args);
![Page 30: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/30.jpg)
Null-conditional operators
if (OnChanged != null)
{
OnChanged(this, args);
}
![Page 31: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/31.jpg)
Null-conditional operators
{
var onChanged = OnChanged;
if (onChanged != null)
{
onChanged(this, args);
}
}
![Page 32: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/32.jpg)
Null-conditional operators
OnChanged?.Invoke(this, args);
![Page 33: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/33.jpg)
The nameof operator
public Point Add(Point point)
{
if (point == null)
{
throw new ArgumentNullException("point");
}
}
![Page 34: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/34.jpg)
The nameof operator
public Point Add(Point other)
{
if (other == null)
{
throw new ArgumentNullException("point");
}
}
![Page 35: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/35.jpg)
The nameof operator
public Point Add(Point point)
{
if (point == null)
{
throw new ArgumentNullException(nameof(point));
}
}
![Page 36: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/36.jpg)
The nameof operator
public Point Add(Point other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
}
![Page 37: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/37.jpg)
Exception filters
try
{
…
}
catch (ConfigurationException e)
{
}
finally
{
}
![Page 38: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/38.jpg)
Exception filters
try
{
…
}
catch (ConfigurationException e) if (e.IsSevere)
{
}
finally
{
}
![Page 39: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/39.jpg)
Await in catch and finally
try
{
…
}
catch (ConfigurationException e) if (e.IsSevere)
{
await LogAsync(e);
}
finally
{
await CloseAsync();
}
![Page 40: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/40.jpg)
roslyn.codeplex.com
Learn more at …
![Page 41: Les nouveautés de C# 6](https://reader034.vdocument.in/reader034/viewer/2022042607/55a779ff1a28ab4c4e8b4575/html5/thumbnails/41.jpg)
© 2015 Microsoft Corporation. All rights reserved.
tech days•
2015
#mstechdays techdays.microsoft.fr