SlideShare a Scribd company logo
1 of 51
6.0
Olav Haugen
Åpen fagkveld - Webstep - 9.10.2014
C-like Object Oriented Language
1999
Anders Hejlsberg
etablerer et team
som skal lage Cool
.NET blir annonsert.
"Cool" har endret navn til C♯
2000
“Mye nærmere C++ i design”
PDC
“Klone av java”
“Mangel på innovasjon”
Andy!
C# 1.0 blir lansert sammen med
.NET 1.0 og Visual Studio .NET 2002
2002
C# 2.0 blir lansert sammen med
.NET 2.0 og Visual Studio 2005
2005
Generics
Partial types
Anonymous methods
Iterators
Nullable types
Getter/setter separate accessibility
Method group conversions (delegates)
Co- and Contra-variance for delegates
Static classes
C# 3.0 blir lansert sammen med
.NET 3.5, LINQ og Visual Studio 2008
2007
Implicitly typed local variables
Object and collection initializers
Auto-Implemented properties
Anonymous types
Extension methods
Query expressions
Lambda expressions
Expression trees
Partial methods
C# 4.0 blir lansert sammen med
.NET 4.0 og Visual Studio 2010
2010
Dynamic binding
Named and optional arguments
Generic co- and contravariance
Embedded interop types ("NoPIA")
C# 5.0 blir lansert samme med
.NET 4.5 og Visual Studio 2012
2012
Asynchronous methods
Caller info attributes
2014
C# 6.0 blir lansert
uten noen features?
C# 6.0
Auto-property enhancements
Primary constructors
Expression bodied function members
Initializers in structs
Using static
Exception filters
Declaration expressions
Nameof expressions
Null-conditional operators
Index initializers
Await in catch and finally blocks
Binary literals and digit separators
Extension Add methods in collection initializers
Improved overload resolution
Roslyn
.NET compiler blir open source
https://roslyn.codeplex.com/
2014
3. juni Visual Studio 2014 CTP
8. juli Visual Studio 2014 CTP 2
18. aug Visual Studio 2014 CTP 3
6. okt Visual Studio 2014 CTP 4
C# 6.0 og .NET tilgjengelig for community før lansering.
Man kan til og med bidra på utvikligen av C#!
6.0
Auto-property
enhancements
Auto-property enhancements
public class User
{
public User()
{
Name = "Olav";
}
public string Name { get; set; }
}
Før: Initialisere public properties
public class User
{
public string Name { get; set; } = "Olav";
}
C# 6.0: Initialisere public properties
Auto-property enhancements
public class User
{
private readonly string _name;
public User()
{
_name = "Olav";
}
public string Name
{
get
{
return _name;
}
}
}
Auto-property enhancements
Før: Initialisere readonly properties
public class User
{
public string Name { get; } = "Olav";
}
Auto-property enhancements
C# 6.0: Initialisere readonly properties
Primary
constructors
public class User
{
private string firstName;
private string lastName;
public User(string firstName, string lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
}
Før:
Primary constructors
public class User(string firstName, string lastName)
{
private string firstName = firstName;
private string lastName = lastName;
}
C# 6.0:
Primary constructors
Primary constructors
public class User(string name)
{
{
if (name == null)
{
throw new
ArgumentNullException("name");
}
}
private string name = name;
}
C# 6.0: Constructor bodies
public class User
{
private readonly string _firstName;
private readonly string _lastName;
public User(string firstName, string lastName)
{
_firstName = firstName;
_lastName = lastName;
}
public string FirstName
{
get
{
return _firstName;
}
}
public string LastName
{
get
{
return _lastName;
}
}
}
Primary constructors
Før: Sette readonly properties
public class User(string firstName, string
lastName)
{
public string FirstName { get; } = firstName;
public string LastName { get; } = lastName;
}
C# 6.0: Sette readonly properties
Primary constructors
Expression bodied
function members
public int Add(int x, int y)
{
return x + y;
}
Før: Enkel metode
Expression bodied function members
public int Add(int x, int y) => x + y;
C# 6.0: Enkel metode
public string Name
{
get
{
return FirstName + " " + LastName;
}
}
Før: Property getter
Expression bodied function members
public string Name => FirstName + " " + LastName;
C# 6.0: Property getter
Null-conditional
operators
public string GetFirstUserName(IEnumerable<Customer> customers)
{
if (customers != null)
{
var customer = customers.FirstOrDefault();
if (customer != null)
{
if (customer.Users != null)
{
var user = customer.Users.FirstOrDefault();
if (user != null)
{
return user.Name;
}
}
}
}
return null;
}
Før:
Null-conditional operators
TO THE RESCUE!
public string GetFirstUserName(IEnumerable<Customer> customers)
{
return customers?.FirstOrDefault()?.Users?.FirstOrDefault()?.Name;
}
C# 6.0:
Null-conditional operators
C# 6.0:
Null-conditional operators
// Null hvis users er null
int? numberOfUsers = users?.Length;
// Null hvis users er null
User first = users?[0];
// Chaining
int? numberOfOrders = users?[0].Orders?.Count();
// Et nytt pattern?
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(X)));
Using static
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello world!");
}
}
Før:
Using static
using System.Console;
class Program
{
static void Main()
{
WriteLine("Hello world!");
}
}
C# 6.0:
Using static
Declaration
expressions
public int ParseIntOrDefault(string numberCandidate)
{
int number;
int.TryParse(numberCandidate, out number);
return number;
}
Før:
Declaration expressions
public int ParseIntOrDefault(string numberCandidate)
{
int.TryParse(numberCandidate, out int number);
return number;
}
C# 6.0:
Declaration expressions
nameof
expressions
nameof expressions
public class Person(string name)
{
{
if (name == null)
throw new ArgumentNullException(nameof(name));
}
}
Skriver ut navnet på variabler og metoder.
Gjør det lettere når man skal refaktorere kode.
WriteLine(nameof(Console.WriteLine)); // Skriver "WriteLine"
WriteLine(nameof(Person.Name)); // Skriver "Name"
Binary literals &
digit separators
Binary literals and digit separators
var bits = 0b0010_1110;
var hex = 0x00_2E;
var dec = 1_234_567_890;
Øker lesbarheten på bits, hex og tall
Exception
filters
Exception filters
try { ... }
catch (MyException e) if (SomeCondition(e))
{
}
Fang en exception basert på en betingelse
Bedre enn å kaste exception videre, siden stacktracen
blir uberørt.
Exception filters
Kan også (mis?)brukes til logging
try { ... }
catch (MyException e) if (Log(e)) {}
public bool Log(Exception e)
{
// Logg exception
// Returner false for at exception ikke catches
return false;
}
Jeg må prøve
C# 6.0 NÅ!
.NET Fiddle
C# 6.0 rett i nettleseren
Visual Studio 2014 CTP
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
…
<LangVersion>experimental</LangVersion>
</PropertyGroup>
Rediger .csproj-fil for å aktivere C# 6.0:
Last ned:
http://www.visualstudio.com/en-us/downloads/visual-studio-14-ctp-vs.aspx
Også tilgjengelig ferdiginstallert i Azure sitt Virtual Machine Gallery
Følg utvikling av C# 6.0
https://roslyn.codeplex.com/
• Følg status på C# features
• Referat fra designmøter
• Fiks bugs
• Foreslå nye features (vil nok mest sannsynlig bli avvist)
olav.haugen@webstep.no

More Related Content

What's hot

Kotlin in action
Kotlin in actionKotlin in action
Kotlin in actionCiro Rizzo
 
Use of Apache Commons and Utilities
Use of Apache Commons and UtilitiesUse of Apache Commons and Utilities
Use of Apache Commons and UtilitiesPramod Kumar
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能についてUehara Junji
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
Cocoaheads Meetup / Kateryna Trofimenko / Feature development
Cocoaheads Meetup / Kateryna Trofimenko / Feature developmentCocoaheads Meetup / Kateryna Trofimenko / Feature development
Cocoaheads Meetup / Kateryna Trofimenko / Feature developmentBadoo Development
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Java libraries you can't afford to miss
Java libraries you can't afford to missJava libraries you can't afford to miss
Java libraries you can't afford to missAndres Almiray
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
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#6Rui Carvalho
 
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 @drpicoxDavid Rodenas
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languagesRafael Winterhalter
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej Sitek
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?intelliyole
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleAnton Arhipov
 

What's hot (19)

Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
 
Use of Apache Commons and Utilities
Use of Apache Commons and UtilitiesUse of Apache Commons and Utilities
Use of Apache Commons and Utilities
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能について
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Cocoaheads Meetup / Kateryna Trofimenko / Feature development
Cocoaheads Meetup / Kateryna Trofimenko / Feature developmentCocoaheads Meetup / Kateryna Trofimenko / Feature development
Cocoaheads Meetup / Kateryna Trofimenko / Feature development
 
JDK Power Tools
JDK Power ToolsJDK Power Tools
JDK Power Tools
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Java libraries you can't afford to miss
Java libraries you can't afford to missJava libraries you can't afford to miss
Java libraries you can't afford to miss
 
Java objects on steroids
Java objects on steroidsJava objects on steroids
Java objects on steroids
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
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
 
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
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
C# - What's Next?
C# - What's Next?C# - What's Next?
C# - What's Next?
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 

Viewers also liked

Viewers also liked (7)

TEACHING WITH VISION
TEACHING WITH VISION TEACHING WITH VISION
TEACHING WITH VISION
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course Introduction
 
C# basics
 C# basics C# basics
C# basics
 
08. Numeral Systems
08. Numeral Systems08. Numeral Systems
08. Numeral Systems
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 

Similar to C# 6.0 Introduction

ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6Andy Butland
 
Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6Paulo Morgado
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptxarjun431527
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116Paulo Morgado
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developerscacois
 
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
 
CAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxCAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxSurajgroupsvideo
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)MongoDB
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma CloudNikolas Burk
 
Retour sur la Microsoft //Build 2018
Retour sur la Microsoft //Build 2018Retour sur la Microsoft //Build 2018
Retour sur la Microsoft //Build 2018Timothé Larivière
 
Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?ColdFusionConference
 
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...DataStax Academy
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехСбертех | SberTech
 
C++ Interface Versioning
C++ Interface VersioningC++ Interface Versioning
C++ Interface VersioningSkills Matter
 
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 slidesDr-archana-dhawan-bajaj
 

Similar to C# 6.0 Introduction (20)

C#.net evolution part 2
C#.net evolution part 2C#.net evolution part 2
C#.net evolution part 2
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
 
Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6
 
classes object fgfhdfgfdgfgfgfgfdoop.pptx
classes object  fgfhdfgfdgfgfgfgfdoop.pptxclasses object  fgfhdfgfdgfgfgfgfdoop.pptx
classes object fgfhdfgfdgfgfgfgfdoop.pptx
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
2012: ql.io and Node.js
2012: ql.io and Node.js2012: ql.io and Node.js
2012: ql.io and Node.js
 
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
 
CAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxCAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptx
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)
 
Managing GraphQL servers with AWS Fargate & Prisma Cloud
Managing GraphQL servers  with AWS Fargate & Prisma CloudManaging GraphQL servers  with AWS Fargate & Prisma Cloud
Managing GraphQL servers with AWS Fargate & Prisma Cloud
 
Retour sur la Microsoft //Build 2018
Retour sur la Microsoft //Build 2018Retour sur la Microsoft //Build 2018
Retour sur la Microsoft //Build 2018
 
What's New in Visual Studio 2008
What's New in Visual Studio 2008What's New in Visual Studio 2008
What's New in Visual Studio 2008
 
C#2
C#2C#2
C#2
 
Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?Dependency Injection Why is it awesome and Why should I care?
Dependency Injection Why is it awesome and Why should I care?
 
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
 
C++ Interface Versioning
C++ Interface VersioningC++ Interface Versioning
C++ Interface Versioning
 
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
 

Recently uploaded

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

C# 6.0 Introduction

  • 1. 6.0 Olav Haugen Åpen fagkveld - Webstep - 9.10.2014
  • 2. C-like Object Oriented Language 1999 Anders Hejlsberg etablerer et team som skal lage Cool
  • 3. .NET blir annonsert. "Cool" har endret navn til C♯ 2000 “Mye nærmere C++ i design” PDC “Klone av java” “Mangel på innovasjon” Andy!
  • 4. C# 1.0 blir lansert sammen med .NET 1.0 og Visual Studio .NET 2002 2002
  • 5. C# 2.0 blir lansert sammen med .NET 2.0 og Visual Studio 2005 2005 Generics Partial types Anonymous methods Iterators Nullable types Getter/setter separate accessibility Method group conversions (delegates) Co- and Contra-variance for delegates Static classes
  • 6. C# 3.0 blir lansert sammen med .NET 3.5, LINQ og Visual Studio 2008 2007 Implicitly typed local variables Object and collection initializers Auto-Implemented properties Anonymous types Extension methods Query expressions Lambda expressions Expression trees Partial methods
  • 7. C# 4.0 blir lansert sammen med .NET 4.0 og Visual Studio 2010 2010 Dynamic binding Named and optional arguments Generic co- and contravariance Embedded interop types ("NoPIA")
  • 8. C# 5.0 blir lansert samme med .NET 4.5 og Visual Studio 2012 2012 Asynchronous methods Caller info attributes
  • 9. 2014 C# 6.0 blir lansert uten noen features?
  • 10.
  • 11. C# 6.0 Auto-property enhancements Primary constructors Expression bodied function members Initializers in structs Using static Exception filters Declaration expressions Nameof expressions Null-conditional operators Index initializers Await in catch and finally blocks Binary literals and digit separators Extension Add methods in collection initializers Improved overload resolution
  • 12. Roslyn .NET compiler blir open source https://roslyn.codeplex.com/
  • 13. 2014 3. juni Visual Studio 2014 CTP 8. juli Visual Studio 2014 CTP 2 18. aug Visual Studio 2014 CTP 3 6. okt Visual Studio 2014 CTP 4 C# 6.0 og .NET tilgjengelig for community før lansering. Man kan til og med bidra på utvikligen av C#!
  • 14. 6.0
  • 16. Auto-property enhancements public class User { public User() { Name = "Olav"; } public string Name { get; set; } } Før: Initialisere public properties
  • 17. public class User { public string Name { get; set; } = "Olav"; } C# 6.0: Initialisere public properties Auto-property enhancements
  • 18. public class User { private readonly string _name; public User() { _name = "Olav"; } public string Name { get { return _name; } } } Auto-property enhancements Før: Initialisere readonly properties
  • 19. public class User { public string Name { get; } = "Olav"; } Auto-property enhancements C# 6.0: Initialisere readonly properties
  • 21. public class User { private string firstName; private string lastName; public User(string firstName, string lastName) { this.firstName = firstName; this.lastName = lastName; } } Før: Primary constructors
  • 22. public class User(string firstName, string lastName) { private string firstName = firstName; private string lastName = lastName; } C# 6.0: Primary constructors
  • 23. Primary constructors public class User(string name) { { if (name == null) { throw new ArgumentNullException("name"); } } private string name = name; } C# 6.0: Constructor bodies
  • 24. public class User { private readonly string _firstName; private readonly string _lastName; public User(string firstName, string lastName) { _firstName = firstName; _lastName = lastName; } public string FirstName { get { return _firstName; } } public string LastName { get { return _lastName; } } } Primary constructors Før: Sette readonly properties
  • 25. public class User(string firstName, string lastName) { public string FirstName { get; } = firstName; public string LastName { get; } = lastName; } C# 6.0: Sette readonly properties Primary constructors
  • 27. public int Add(int x, int y) { return x + y; } Før: Enkel metode Expression bodied function members public int Add(int x, int y) => x + y; C# 6.0: Enkel metode
  • 28. public string Name { get { return FirstName + " " + LastName; } } Før: Property getter Expression bodied function members public string Name => FirstName + " " + LastName; C# 6.0: Property getter
  • 30. public string GetFirstUserName(IEnumerable<Customer> customers) { if (customers != null) { var customer = customers.FirstOrDefault(); if (customer != null) { if (customer.Users != null) { var user = customer.Users.FirstOrDefault(); if (user != null) { return user.Name; } } } } return null; } Før: Null-conditional operators
  • 32. public string GetFirstUserName(IEnumerable<Customer> customers) { return customers?.FirstOrDefault()?.Users?.FirstOrDefault()?.Name; } C# 6.0: Null-conditional operators
  • 33. C# 6.0: Null-conditional operators // Null hvis users er null int? numberOfUsers = users?.Length; // Null hvis users er null User first = users?[0]; // Chaining int? numberOfOrders = users?[0].Orders?.Count(); // Et nytt pattern? PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(X)));
  • 35. using System; class Program { static void Main() { Console.WriteLine("Hello world!"); } } Før: Using static
  • 36. using System.Console; class Program { static void Main() { WriteLine("Hello world!"); } } C# 6.0: Using static
  • 38. public int ParseIntOrDefault(string numberCandidate) { int number; int.TryParse(numberCandidate, out number); return number; } Før: Declaration expressions
  • 39. public int ParseIntOrDefault(string numberCandidate) { int.TryParse(numberCandidate, out int number); return number; } C# 6.0: Declaration expressions
  • 41. nameof expressions public class Person(string name) { { if (name == null) throw new ArgumentNullException(nameof(name)); } } Skriver ut navnet på variabler og metoder. Gjør det lettere når man skal refaktorere kode. WriteLine(nameof(Console.WriteLine)); // Skriver "WriteLine" WriteLine(nameof(Person.Name)); // Skriver "Name"
  • 43. Binary literals and digit separators var bits = 0b0010_1110; var hex = 0x00_2E; var dec = 1_234_567_890; Øker lesbarheten på bits, hex og tall
  • 45. Exception filters try { ... } catch (MyException e) if (SomeCondition(e)) { } Fang en exception basert på en betingelse Bedre enn å kaste exception videre, siden stacktracen blir uberørt.
  • 46. Exception filters Kan også (mis?)brukes til logging try { ... } catch (MyException e) if (Log(e)) {} public bool Log(Exception e) { // Logg exception // Returner false for at exception ikke catches return false; }
  • 47. Jeg må prøve C# 6.0 NÅ!
  • 48. .NET Fiddle C# 6.0 rett i nettleseren
  • 49. Visual Studio 2014 CTP <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> … <LangVersion>experimental</LangVersion> </PropertyGroup> Rediger .csproj-fil for å aktivere C# 6.0: Last ned: http://www.visualstudio.com/en-us/downloads/visual-studio-14-ctp-vs.aspx Også tilgjengelig ferdiginstallert i Azure sitt Virtual Machine Gallery
  • 50. Følg utvikling av C# 6.0 https://roslyn.codeplex.com/ • Følg status på C# features • Referat fra designmøter • Fiks bugs • Foreslå nye features (vil nok mest sannsynlig bli avvist)

Editor's Notes

  1. Anders Hejlsberg - mannen bak Turbo Pascal og Delphi
  2. November 2007
  3. Før
  4. C# 6.0
  5. Før Viktig hvis man skal lage immutable objekter
  6. C# 6.0 Det lages automatisk backing fields for Name propertien. Ved å fjerne “set;” vil den også markeres som “readonly”
  7. Før
  8. C# 6.0 Primary constructor argumenter lever i et eget scope for initialisering. Man kan ha samme navn på type members. Samme syntax gjelder også for structs
  9. C# 6.0
  10. Før
  11. C# 6.0
  12. Kan også definere operatorer inline
  13. Før
  14. Før
  15. C# 6.0 - Hvis det man setter ? foran er null, stopper kjeden og returnerer
  16. C# 6.0
  17. Før
  18. C# 6.0
  19. Før
  20. C# 6.0 - Kan også være spesielt nyttig i LINQ-spørringer
  21. Hvis man er MDSN subscriber har man gratis minutter /mnd