SlideShare a Scribd company logo
C# 6.0
The new stuff
Chris Skardon
@cskardon | chris@tournr.com
The haps
• Auto-properties
• String Interpolation
• Null Conditional Operator
• Expression-bodied functions
• using static
• nameof
• Index Initializers
• Exception filters
• await in catch/finally
Auto properties
Auto Properties
• Woah! That’s C# 3.0, bad start Chris, bad start
public int AutoProperty { get; set; }
• Auto properties++
• Added Initializers
• Backing fields are actually readonly
public class AutoProperties
{
public int SetInConstructorNoNeedForSet { get; }
public AutoProperties(int value)
{
SetInConstructorNoNeedForSet = value;
}
}
public string ReadonlyProperty { get; } = "I'm Readonly!";
Examples!
public DateTime NotJustConsts { get; } = DateTime.Now;
public int UsingLambda => 1 + 2;
Why?
• To save code
• To get actual readonly Properties
• Without the need to use backing fields
String Interpolation
String Interpolation
• Inline string expression handling
$"{X}"
Examples!
const string name = "Chris";
string oldWay = string.Format("Hello {0}", name);
string newWay = $"Hello {name}";
Why?
• Again – save code
• Easier to read
• Helps with the introduction of new content in a
string
• Don’t have to re-order string.Format arguments
Null Conditional Operator
Null Conditional Operator
• Looks for Null before continuing execution
• Short-Circuit behaviour
?.
Examples!
public static int GetLength(string value)
{
if(value == null)
return -1;
return value.Length;
}
public static int GetLength(string value)
{
return ?? -1;
}
value?.Length
Why?
• Remove cumbersome null checks
• Multiple null checks in one line
if (user != null)
{
if (user.FirstName != null)
{
return user.FirstName.Length;
}
}
user?.FirstName?.Length
Expression-bodied functions
Expression-bodied functions
• Single line methods don’t need all the gubbins
Examples!
public static int GetLength(string value)
{
return value?.Length ?? -1;
}
public int GetLength(string value) => value?.Length ?? -1;
Why?
• Code size
• Simplifies ‘one-liners’
using static
using static
• Are you fed up of typing ‘Math.’?
• Of course you are!
Examples!
using static System.Math;
Console.WriteLine(Abs(10-12));
WriteLine(Abs(10-12));
using static System.Console;
Console.WriteLine(Math.Abs(10-12));
Why?
• If you’re doing a lot of ‘Console.’ or ‘Math.’
it can make the code nicer
nameof
nameof
• Gets the name of a given
field/property/argument
Examples!
public void ThrowIf(string value)
{
if(string.IsNullOrWhiteSpace(value))
throw new ArgumentException("Value can't be empty or null!", nameof(value));
}
public static class Config
{
public static class Email
{
public static string To => $"{nameof(Email)}.{nameof(To)}";
}
}
ConfigurationManager.AppSettings[Config.Email.To].Value;
ConfigurationManager.AppSettings["Email.To"].Value;
Why?
• Refactoring argument names / class names
• Messages no longer out of sync
• Particularly good for ArgumentException instances
• Config using strong types
Index Initializers
Index Initializers
• Allow you to set the values in the construction
of a Dictionary by key.
Examples!
var x = new Dictionary<object, object>
{
[1] = "one",
["ten"] = 10
};
var x = new Dictionary<int, string>
{
[1] = "one",
[10] = "ten"
};
Exception Filters
Exception Filters
• We’ve been able to filter on Exception types
forever
• Now we can filter by the content of those
exceptions
Examples!
try
{
throw new ArgumentNullException("arg1");
}
catch (ArgumentNullException e) when (e.ParamName == "arg1")
{
Console.WriteLine("Caught Arg1");
}
catch (ArgumentNullException e)
{
Console.WriteLine($"Caught {e.ParamName}");
}
Why?
• To filter out conditions you can safely retry
with
• To abuse and do logging with exceptions:
catch (ArgumentNullException e) when (Log(e))
{
Console.WriteLine("Caught Arg1");
}
await in catch/finally
await in catch/finally
• Pretty self explanatory
• In C#5.0 you couldn’t use ‘await’ in a
catch/finally block
• Now you can!
Examples!
try
{
throw new ArgumentNullException("arg1");
}
catch (ArgumentNullException e)
{
await LogAsync(e);
}
Why?
• So you don’t have non-async code in your fully
async work!
The End.
Questions?
@cskardon | chris@tournr.com

More Related Content

What's hot

Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
Dmitri Nesteruk
 
PostThis
PostThisPostThis
PostThis
testingphase
 
Intro to C++
Intro to C++Intro to C++
Intro to C++
Ahmed Farag
 
Command line arguments that make you smile
Command line arguments that make you smileCommand line arguments that make you smile
Command line arguments that make you smile
Martin Melin
 
Echtzeitapplikationen mit Elixir und GraphQL
Echtzeitapplikationen mit Elixir und GraphQLEchtzeitapplikationen mit Elixir und GraphQL
Echtzeitapplikationen mit Elixir und GraphQL
Moritz Flucht
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magic
Badoo Development
 
Getting rid of backtracking
Getting rid of backtrackingGetting rid of backtracking
Getting rid of backtracking
Dr. Jan Köhnlein
 
Theads services
Theads servicesTheads services
Theads services
Training Guide
 
Actividad N° 6 - Unidad 4
Actividad N° 6 - Unidad 4Actividad N° 6 - Unidad 4
Actividad N° 6 - Unidad 4
Pablo Agustin Novillo Audicio
 
Functional programming in Javascript
Functional programming in JavascriptFunctional programming in Javascript
Functional programming in Javascript
Knoldus Inc.
 
MTL Versus Free
MTL Versus FreeMTL Versus Free
MTL Versus Free
John De Goes
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
aragozin
 
Java Week4(B) Notepad
Java Week4(B)   NotepadJava Week4(B)   Notepad
Java Week4(B) Notepad
Chaitanya Rajkumar Limmala
 
Function, Class
Function, ClassFunction, Class
Function, Class
Hirakawa Akira
 
Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor
John(Qiang) Zhang
 
Queues
QueuesQueues
Linq inside out
Linq inside outLinq inside out
Linq inside out
Andries Nieuwenhuize
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
piyush Kumar Sharma
 
Profiling in python
Profiling in pythonProfiling in python
Profiling in python
John(Qiang) Zhang
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
Sumant Tambe
 

What's hot (20)

Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
 
PostThis
PostThisPostThis
PostThis
 
Intro to C++
Intro to C++Intro to C++
Intro to C++
 
Command line arguments that make you smile
Command line arguments that make you smileCommand line arguments that make you smile
Command line arguments that make you smile
 
Echtzeitapplikationen mit Elixir und GraphQL
Echtzeitapplikationen mit Elixir und GraphQLEchtzeitapplikationen mit Elixir und GraphQL
Echtzeitapplikationen mit Elixir und GraphQL
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magic
 
Getting rid of backtracking
Getting rid of backtrackingGetting rid of backtracking
Getting rid of backtracking
 
Theads services
Theads servicesTheads services
Theads services
 
Actividad N° 6 - Unidad 4
Actividad N° 6 - Unidad 4Actividad N° 6 - Unidad 4
Actividad N° 6 - Unidad 4
 
Functional programming in Javascript
Functional programming in JavascriptFunctional programming in Javascript
Functional programming in Javascript
 
MTL Versus Free
MTL Versus FreeMTL Versus Free
MTL Versus Free
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
 
Java Week4(B) Notepad
Java Week4(B)   NotepadJava Week4(B)   Notepad
Java Week4(B) Notepad
 
Function, Class
Function, ClassFunction, Class
Function, Class
 
Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor
 
Queues
QueuesQueues
Queues
 
Linq inside out
Linq inside outLinq inside out
Linq inside out
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Profiling in python
Profiling in pythonProfiling in python
Profiling in python
 
Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 

Similar to C#6 - The New Stuff

DotNet programming & Practices
DotNet programming & PracticesDotNet programming & Practices
DotNet programming & Practices
Dev Raj Gautam
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 development
Fisnik Doko
 
Clean up your code with C#6
Clean up your code with C#6Clean up your code with C#6
Clean up your code with C#6
Rui Carvalho
 
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
Christian Nagel
 
C# - What's next
C# - What's nextC# - What's next
C# - What's next
Christian Nagel
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
Andy Butland
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
David Rodenas
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
Christian Nagel
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
Codemotion
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
Eduard Tomàs
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
Chhom Karath
 
Modern C++
Modern C++Modern C++
Modern C++
Michael Clark
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
Kevin Pilch
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and Java
Ali MasudianPour
 
Constructor
ConstructorConstructor
Constructor
abhay singh
 
Dr archana dhawan bajaj - csharp fundamentals slides
Dr archana dhawan bajaj - csharp fundamentals slidesDr archana dhawan bajaj - csharp fundamentals slides
Dr archana dhawan bajaj - csharp fundamentals slides
Dr-archana-dhawan-bajaj
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
jeffz
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
Michael Heron
 
Introduction to c#
Introduction to c#Introduction to c#
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0
William Munn
 

Similar to C#6 - The New Stuff (20)

DotNet programming & Practices
DotNet programming & PracticesDotNet programming & Practices
DotNet programming & Practices
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 development
 
Clean up your code with C#6
Clean up your code with C#6Clean up your code with C#6
Clean up your code with C#6
 
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
 
C# - What's next
C# - What's nextC# - What's next
C# - What's next
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
Modern C++
Modern C++Modern C++
Modern C++
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 
A comparison between C# and Java
A comparison between C# and JavaA comparison between C# and Java
A comparison between C# and Java
 
Constructor
ConstructorConstructor
Constructor
 
Dr archana dhawan bajaj - csharp fundamentals slides
Dr archana dhawan bajaj - csharp fundamentals slidesDr archana dhawan bajaj - csharp fundamentals slides
Dr archana dhawan bajaj - csharp fundamentals slides
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0
 

Recently uploaded

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 

C#6 - The New Stuff

Editor's Notes

  1. https://msdn.microsoft.com/en-gb/magazine/dn802602.aspx https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6
  2. The only way in previous versions of C# to do a readonly property was to use a backing field like: private int _backing = 10; public int Readonly { get { return _backing; } } Which was a lot of extra code around a field, the ol’ faithful of ‘{ get; private set; }’ wasn’t truly readonly as you could set it via reflection. With things like optional parameters, you have to use constant values (so actual strings, not things that are resolved at runtime) with property initializers – you can use any value Even Lambda! This last example really shows another way to do readonly – as we know readonly can only be set via the field or constructor, you can’t set it at any other time, so for those constructor set properties – you can still go full readonly and not need a backing field.
  3. This ‘To Save Code’ thing is going to turn up a lot Readonly is important as a security/performance thingy
  4. $ tells the compiler you’re going to start, and each var you want to be displayed should be placed in curly braces.
  5. A little contrived as let’s face it, you would never do this, but here we have the old way of doing strings – using string.Format. We all know why we use string.Format as opposed to just a straight concat right? (not always needed if you’re doing small bits of work that’s not repeated.
  6. Hey look – Save code!!! Easier to read – obviously this comes down to personal preference, but it’s invaluable in writing some things (such as Cypher for Neo4j). Ever had to insert a new bit in? i.e. from ‘Hello Chris’ to ‘Hello {SALUTATION} {NAME}’ and then had to re-order the parameters? OK for 2 parameters that’s alright – but when you get to larger numbers – ARGH!
  7. Short-circuit like && or || is a short circuit call – if the thing being operated on *is* null, then the execution just returns null, and doesn’t continue.
  8. You’d never write this method – or would you??? Anyhews – does basic checks, returns -1 for bad values (mebbe an exception would be better?) Still – 3 lines – we *can* improve, using the null conditional operator (C#4 mebbe 5) and the null-coalescing operator, giving us one line. The important bit in this case, is that if ‘value’ is null, then you can treat the entire value?.Length as null.
  9. Obvs this removes the big null checks – but another bonus is the ability to chain those null checks – provided you don’t care what the null object was, and simply want the answer.
  10. So this is basically the same as the Auto-Properties – but with the addition of parameters – in reality – the Lambda example for AutoProperties could have easily been here, as its full title is ‘Expression Bodied Function Members’ and that Auto Property was an expression bodied member. In truth, we’ve not actually lost any characters – {} is the same as => in count truth be told – I’ve never really used this
  11. It’s always the code-size – but only vertically, not in character count (in that example) – To be honest, I slightly struggle with this – it’s useful for properties, but I see little gain with methods unless you particularly dislike curly braces (in which case – wrong language!)
  12. Math.XX is odd as in general day-to-day business code – you don’t tend to actually use it that often, but we all know it’s there, so it’s as good an example as any… Anyways – using static allows you to use static classes without the static identifier – so Math.Abs can be just ‘Abs’ Let’s see it in all it’s glory!
  13. This is the basic ‘Abs’ method – which returns the Absolute (+ve) value of a number, so a -2 becomes 2. This is the common way to write something like this – verbose. Let’s add a using static (in the same place you would with your other usings) Now we can have this! Oh but wait – Console is also a static class – let’s use that bad boy. Boom?
  14. Config - No accidental mispellings