SlideShare ist ein Scribd-Unternehmen logo
1 von 45
C# 6.0 April 2014 Preview
Paulo Morgado
http://netponto.org47ª Reunião Lisboa - 31/05/2014
Who Am I?
Paulo Morgado
CodePlex
Revista
PROGRAMAR
Agenda
• C# Evolution
• .NET Compiler Platform (“Roslyn”)
• C# 6.0 Features
• Demos
C# 1.0
Managed
C# 2.0
Generics
C# 3.0
LINQ
C# 4.0
Dynamic
Programming
C# 5.0
Asynchronous
Programming
Windows Runtime
C# 6.0
Compiler Platform
“Roslyn”
C# Evolution
.NET Compiler Platform (“Roslyn”)
A reimplementation of C# and VB compilers
In C# and VB
With rich public APIs
On CodePlex
Why “Roslyn”?
C# 6.0 Features
Disclaimer:
At this point, some of the features are
implemente, others are planned and others
are being considered.
public class Customer
{
public string FirstName { get; private set; }
public string LastName { get; private set; }
}
public class Customer
{
public string FirstName { get; private set; } = "John";
public string LastName { get; private set; } = "Doe";
}
Auto-Property Initializers
public class Customer
{
public string FirstName { get; } = "John";
public string LastName { get; } = "Doe";
}
Primary Constructors
Class and Struct Parameters
public class Customer
{
private string firstName;
private string lastName;
public Customer(string firstName, string lastName)
{
this.nome = firstName;
this.lastName = lastName;
}
public string FirstName { get { return firstName; } }
public string LastName { get { return lastName; } }
}
public class Customer
{
private string firstName;
private string lastName;
public Customer(string firstName, string lastName)
{
this.nome = firstName;
this.lastName = lastName;
}
public string FirstName { get { return firstName; } }
public string LastName { get { return lastName; } }
}
public class Customer(string firstName, string lastName)
{
public string FirstName { get; } = firstName;
public string LatName { get; } = lastName;
}
Primary Constructors
Field Parameters
public class Customer(
string firstName,
string lastName,
DateTime birthDate)
{
public string FirstName { get; } = firstName;
public string LatName { get; } = lastName;
private DateTime _birthDate = birthDate;
}
public class Customer(
string firstName,
string lastName,
DateTime birthDate)
{
public string FirstName { get; } = firstName;
public string LatName { get; } = lastName;
private DateTime _birthDate = birthDate;
}
public class Customer(
string firstName,
string lastName,
private DateTime birthDate)
{
public string FirstName { get; } = firstName;
public string LatName { get; } = lastName;
}
public class Customer(
string firstName,
string lastName,
private DateTime birthDate)
{
public string FirstName { get; } = firstName;
public string LatName { get; } = lastName;
public int Age
{
get { return CalcularAge(birthDate); }
}
}
Primary Constructors
Explicit Constructors
public Point()
: this(0, 0) // calls the primary constructor
{
}
Primary Constructors
Base Initializer
class BufferFullException()
: Exception("Buffer full")
{
}
Primary Constructors
Partial Types
If a class is declared in multiple parts, only one
of those parts can declare a constructor
parameters and only that part can declare
parameters on the specification of the base
class.
Using Static
using System;
class Program
{
static void Main()
{
Console.WriteLine(Math.Sqrt(3 * 3 + 4 * 4));
}
}
using System;
class Program
{
static void Main()
{
Console.WriteLine(Math.Sqrt(3 * 3 + 4 * 4));
}
}
using System.Console;
using System.Math;
class Program
{
static void Main()
{
WriteLine(Sqrt(3 * 3 + 4 * 4));
}
}
Using Static
Extension Methods
using System.Linq.Enumerable; // Just the type, not the whole namespace
class Program
{
static void Main()
{
var range = Range(5, 17);
var odd = Where(range, i => i % 2 == 1);
var even = range.Where(i => i % 2 == 0);
}
}
using System.Linq.Enumerable; // Just the type, not the whole namespace
class Program
{
static void Main()
{
var range = Range(5, 17); // Allowed
var odd = Where(range, i => i % 2 == 1); // Not Allowed
var even = range.Where(i => i % 2 == 0); // Allowed
}
}
Declaration Expressions
if (int.TryParse(s, out int i)) { … }
GetCoordinates(out var x, out var y);
Console.WriteLine("Result: {0}", (int x = GetValue()) * x);
if ((string s = o as string) != null) { … s … }
from s in strings
select int.TryParse(s, out int i) ? i : -1;
Excpetion Filters
try
{
…
}
catch (Exception e) if (myfilter(e))
{
…
}
Binary Literals
var bits = 0b00101110;
Digit Separators
var bits = 0b0010_1110;
var hex = 0x00_2E;
var dec = 1_234_567_890;
Extension Add Methods in Collection
Initializers
On the first implementation of collection initializers in C#,
the Add methods that get called couldn’t be extension
methods.
VB got it right from the start, but it seems C# had been
forgoten.
This has been fixed: the code generated from a collection
initializer will now happily call an extension method called
Add.
It’s not much of a feature, but it’s occasionally useful, and it
turned out implementing it in the new compiler amounted
to removing a check that prevented it.
Element Initializers
var numbers = new Dictionary<int, string>
{
[7] = “seven",
[9] = “nine",
[13] = “thirteen"
};
Indexed Members
var customer = new JsonData
{
$first = "Anders", // => ["first"] = "Anders"
$last = "Hejlsberg" // => ["last"] = "Hejlsberg"
};
string first = customer.$first; // => customer["first"]
Await in catch and finally blocks
Resource res = null;
try
{
// You could do this.
res = await res.OpenAsync(…);
…
}
catch (ResourceException e)
{
// Now you can do this …
await res.LogAsync(res, e);
}
finally
{
// … and this.
if (res != null) await res.CloseAsync();
}
Expression-Bodied Members
public class Point(int x, int y)
{
public int X => x;
public int Y => y;
public double Dist => Math.Sqrt(x* x + y* y);
public Point Move(int dx, int dy) => new Point(x + dx, y + dy);
}
Event Initializers
var button = new Button
{
...
Click += (source, e) => ...
...
};
Semicolon Operator
(var x = Foo(); Write(x); x*x)
Params IEnumerable
int Avg(params IEnumerable<int> numbers) { … }
String Interpolation
"{p.First} {p.Last} is {p.Age} years old."
discussion
NameOf Operator
string s = nameof(Console.Write);
Null Propagation
var temp = GetCustomer();
string name = (temp == null) ? null : temp.Name;
var temp = GetCustomer()?.Name;
Null Propagation
Associativity
– Left associative
• ((a?.b)?.c)
– Right associative
• (a?.(b?.c))
int? l = customer?.Nome.Length;
discussion
Protected and Internal
protected internal
protected internal
protectedinternal
discussion
Questions?
Call to action
• Use the IDE and language features
• Dip your toes in custom diagnostics
• Consider forking the compiler source
• Give feedback
References
MSDN
– http://www.msdn.com/roslyn
Download Preview
– http://aka.ms/Roslyn
CodePlex
– http://roslyn.codeplex.com/
Roslyn source browser
– http://source.roslyn.codeplex.com/
References
The Future of C# - //build/ 2014
– http://channel9.msdn.com/Events/Build/2014/2-577
What’s New for C# Developers - //build/ 2014
– http://channel9.msdn.com/Events/Build/2014/9-020
Anders Hejlsberg Live Q&A - //build/ 2014
– http://channel9.msdn.com/Events/Build/2014/9-010
The Future of Visual Basic and C# - TechEd North America 2014
– http://channel9.msdn.com/Events/TechEd/NorthAmerica/2014/DEV-B336
Channel 9 Live: .NET Framework Q&A - TechEd North America 2014
– http://channel9.msdn.com/Events/TechEd/NorthAmerica/2014/C9-22
References
C# – Novas Funcionalidades do C# 6.0 – Antevisão de Abril de 2014
– http://www.revista-programar.info/artigos/c-novas-funcionalidades-do-c-6-0-antevisao-de-abril-
de-2014/
A C# 6.0 Language Preview
– http://msdn.microsoft.com/en-us/magazine/dn683793.aspx
Questões?
Obrigado!
Paulo Morgado
http://PauloMorgado.NET/
https://twitter.com/PauloMorgado
https://www.facebook.com/PauloMorgado.NET
http://www.slideshare.net/PauloJorgeMorgado
Patrocinadores “GOLD”
Twitter: @PTMicrosoft http://www.microsoft.com/portugal
Patrocinadores “Silver”
Patrocinadores “Bronze”
http://bit.ly/netponto-aval-47
* Para quem não puder preencher durante a reunião,
iremos enviar um email com o link à tarde
Próximas reuniões presenciais
31/05/2014 – Maio (Lisboa)
21/06/2014 – Junho (Lisboa)
27/07/2014 – Julho (Lisboa)
??/??/???? – ????? (Porto)
Reserva estes dias na agenda! :)

Weitere ähnliche Inhalte

Was ist angesagt?

Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semesterDOSONKA Group
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manualPrabhu D
 
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
 
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.Abu Saleh
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 
Virtual function
Virtual functionVirtual function
Virtual functionharman kaur
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphismmohamed sikander
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsAlfonso Peletier
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsPrincess Sam
 

Was ist angesagt? (20)

Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
C++11
C++11C++11
C++11
 
Java practical
Java practicalJava practical
Java practical
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
OOP Core Concept
OOP Core ConceptOOP Core Concept
OOP Core Concept
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
 
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
 
Constructor,destructors cpp
Constructor,destructors cppConstructor,destructors cpp
Constructor,destructors cpp
 
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
Inheritance and polymorphism
Inheritance and polymorphismInheritance and polymorphism
Inheritance and polymorphism
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
C++11
C++11C++11
C++11
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
 
C++11
C++11C++11
C++11
 

Ähnlich wie C# 6.0 - April 2014 preview

Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»SpbDotNet Community
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
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
 
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
 
Practices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerPractices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerSrikanth Shreenivas
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionHans Höchtl
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8franciscoortin
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfShashikantSathe3
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 

Ähnlich wie C# 6.0 - April 2014 preview (20)

Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
New C# features
New C# featuresNew C# features
New C# features
 
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
 
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
 
Practices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerPractices For Becoming A Better Programmer
Practices For Becoming A Better Programmer
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Java practical
Java practicalJava practical
Java practical
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
C# 6.0 Preview
C# 6.0 PreviewC# 6.0 Preview
C# 6.0 Preview
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
 
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdfLECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
LECTURE 2 MORE TYPES, METHODS, CONDITIONALS.pdf
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 

Mehr von Paulo Morgado

NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Paulo Morgado
 
await Xamarin @ PTXug
await Xamarin @ PTXugawait Xamarin @ PTXug
await Xamarin @ PTXugPaulo Morgado
 
MVP Showcase 2015 - C#
MVP Showcase 2015 - C#MVP Showcase 2015 - C#
MVP Showcase 2015 - C#Paulo Morgado
 
Roslyn analyzers: File->New->Project
Roslyn analyzers: File->New->ProjectRoslyn analyzers: File->New->Project
Roslyn analyzers: File->New->ProjectPaulo Morgado
 
Async-await best practices in 10 minutes
Async-await best practices in 10 minutesAsync-await best practices in 10 minutes
Async-await best practices in 10 minutesPaulo Morgado
 
What’s New In C# 5.0 - iseltech'13
What’s New In C# 5.0 - iseltech'13What’s New In C# 5.0 - iseltech'13
What’s New In C# 5.0 - iseltech'13Paulo Morgado
 
What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013Paulo Morgado
 
What's new in c# 5.0 net ponto
What's new in c# 5.0   net pontoWhat's new in c# 5.0   net ponto
What's new in c# 5.0 net pontoPaulo Morgado
 
What's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutWhat's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutPaulo Morgado
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoPaulo Morgado
 
As Novidades Do C# 4.0 - NetPonto
As Novidades Do C# 4.0 - NetPontoAs Novidades Do C# 4.0 - NetPonto
As Novidades Do C# 4.0 - NetPontoPaulo Morgado
 

Mehr von Paulo Morgado (12)

NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#
 
await Xamarin @ PTXug
await Xamarin @ PTXugawait Xamarin @ PTXug
await Xamarin @ PTXug
 
MVP Showcase 2015 - C#
MVP Showcase 2015 - C#MVP Showcase 2015 - C#
MVP Showcase 2015 - C#
 
Roslyn analyzers: File->New->Project
Roslyn analyzers: File->New->ProjectRoslyn analyzers: File->New->Project
Roslyn analyzers: File->New->Project
 
Async-await best practices in 10 minutes
Async-await best practices in 10 minutesAsync-await best practices in 10 minutes
Async-await best practices in 10 minutes
 
What’s New In C# 5.0 - iseltech'13
What’s New In C# 5.0 - iseltech'13What’s New In C# 5.0 - iseltech'13
What’s New In C# 5.0 - iseltech'13
 
What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013
 
What's new in c# 5.0 net ponto
What's new in c# 5.0   net pontoWhat's new in c# 5.0   net ponto
What's new in c# 5.0 net ponto
 
What's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOutWhat's New In C# 5.0 - Rumos InsideOut
What's New In C# 5.0 - Rumos InsideOut
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPonto
 
As Novidades Do C# 4.0 - NetPonto
As Novidades Do C# 4.0 - NetPontoAs Novidades Do C# 4.0 - NetPonto
As Novidades Do C# 4.0 - NetPonto
 

Kürzlich hochgeladen

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
[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
 

Kürzlich hochgeladen (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
[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
 

C# 6.0 - April 2014 preview

  • 1. C# 6.0 April 2014 Preview Paulo Morgado http://netponto.org47ª Reunião Lisboa - 31/05/2014
  • 2. Who Am I? Paulo Morgado CodePlex Revista PROGRAMAR
  • 3. Agenda • C# Evolution • .NET Compiler Platform (“Roslyn”) • C# 6.0 Features • Demos
  • 4. C# 1.0 Managed C# 2.0 Generics C# 3.0 LINQ C# 4.0 Dynamic Programming C# 5.0 Asynchronous Programming Windows Runtime C# 6.0 Compiler Platform “Roslyn” C# Evolution
  • 5. .NET Compiler Platform (“Roslyn”) A reimplementation of C# and VB compilers In C# and VB With rich public APIs On CodePlex
  • 7. C# 6.0 Features Disclaimer: At this point, some of the features are implemente, others are planned and others are being considered.
  • 8. public class Customer { public string FirstName { get; private set; } public string LastName { get; private set; } } public class Customer { public string FirstName { get; private set; } = "John"; public string LastName { get; private set; } = "Doe"; } Auto-Property Initializers public class Customer { public string FirstName { get; } = "John"; public string LastName { get; } = "Doe"; }
  • 9. Primary Constructors Class and Struct Parameters public class Customer { private string firstName; private string lastName; public Customer(string firstName, string lastName) { this.nome = firstName; this.lastName = lastName; } public string FirstName { get { return firstName; } } public string LastName { get { return lastName; } } } public class Customer { private string firstName; private string lastName; public Customer(string firstName, string lastName) { this.nome = firstName; this.lastName = lastName; } public string FirstName { get { return firstName; } } public string LastName { get { return lastName; } } } public class Customer(string firstName, string lastName) { public string FirstName { get; } = firstName; public string LatName { get; } = lastName; }
  • 10. Primary Constructors Field Parameters public class Customer( string firstName, string lastName, DateTime birthDate) { public string FirstName { get; } = firstName; public string LatName { get; } = lastName; private DateTime _birthDate = birthDate; } public class Customer( string firstName, string lastName, DateTime birthDate) { public string FirstName { get; } = firstName; public string LatName { get; } = lastName; private DateTime _birthDate = birthDate; } public class Customer( string firstName, string lastName, private DateTime birthDate) { public string FirstName { get; } = firstName; public string LatName { get; } = lastName; } public class Customer( string firstName, string lastName, private DateTime birthDate) { public string FirstName { get; } = firstName; public string LatName { get; } = lastName; public int Age { get { return CalcularAge(birthDate); } } }
  • 11. Primary Constructors Explicit Constructors public Point() : this(0, 0) // calls the primary constructor { }
  • 12. Primary Constructors Base Initializer class BufferFullException() : Exception("Buffer full") { }
  • 13. Primary Constructors Partial Types If a class is declared in multiple parts, only one of those parts can declare a constructor parameters and only that part can declare parameters on the specification of the base class.
  • 14. Using Static using System; class Program { static void Main() { Console.WriteLine(Math.Sqrt(3 * 3 + 4 * 4)); } } using System; class Program { static void Main() { Console.WriteLine(Math.Sqrt(3 * 3 + 4 * 4)); } } using System.Console; using System.Math; class Program { static void Main() { WriteLine(Sqrt(3 * 3 + 4 * 4)); } }
  • 15. Using Static Extension Methods using System.Linq.Enumerable; // Just the type, not the whole namespace class Program { static void Main() { var range = Range(5, 17); var odd = Where(range, i => i % 2 == 1); var even = range.Where(i => i % 2 == 0); } } using System.Linq.Enumerable; // Just the type, not the whole namespace class Program { static void Main() { var range = Range(5, 17); // Allowed var odd = Where(range, i => i % 2 == 1); // Not Allowed var even = range.Where(i => i % 2 == 0); // Allowed } }
  • 16. Declaration Expressions if (int.TryParse(s, out int i)) { … } GetCoordinates(out var x, out var y); Console.WriteLine("Result: {0}", (int x = GetValue()) * x); if ((string s = o as string) != null) { … s … } from s in strings select int.TryParse(s, out int i) ? i : -1;
  • 17. Excpetion Filters try { … } catch (Exception e) if (myfilter(e)) { … }
  • 18. Binary Literals var bits = 0b00101110;
  • 19. Digit Separators var bits = 0b0010_1110; var hex = 0x00_2E; var dec = 1_234_567_890;
  • 20. Extension Add Methods in Collection Initializers On the first implementation of collection initializers in C#, the Add methods that get called couldn’t be extension methods. VB got it right from the start, but it seems C# had been forgoten. This has been fixed: the code generated from a collection initializer will now happily call an extension method called Add. It’s not much of a feature, but it’s occasionally useful, and it turned out implementing it in the new compiler amounted to removing a check that prevented it.
  • 21. Element Initializers var numbers = new Dictionary<int, string> { [7] = “seven", [9] = “nine", [13] = “thirteen" };
  • 22. Indexed Members var customer = new JsonData { $first = "Anders", // => ["first"] = "Anders" $last = "Hejlsberg" // => ["last"] = "Hejlsberg" }; string first = customer.$first; // => customer["first"]
  • 23. Await in catch and finally blocks Resource res = null; try { // You could do this. res = await res.OpenAsync(…); … } catch (ResourceException e) { // Now you can do this … await res.LogAsync(res, e); } finally { // … and this. if (res != null) await res.CloseAsync(); }
  • 24. Expression-Bodied Members public class Point(int x, int y) { public int X => x; public int Y => y; public double Dist => Math.Sqrt(x* x + y* y); public Point Move(int dx, int dy) => new Point(x + dx, y + dy); }
  • 25. Event Initializers var button = new Button { ... Click += (source, e) => ... ... };
  • 26. Semicolon Operator (var x = Foo(); Write(x); x*x)
  • 27. Params IEnumerable int Avg(params IEnumerable<int> numbers) { … }
  • 28. String Interpolation "{p.First} {p.Last} is {p.Age} years old." discussion
  • 29. NameOf Operator string s = nameof(Console.Write);
  • 30. Null Propagation var temp = GetCustomer(); string name = (temp == null) ? null : temp.Name; var temp = GetCustomer()?.Name;
  • 31. Null Propagation Associativity – Left associative • ((a?.b)?.c) – Right associative • (a?.(b?.c)) int? l = customer?.Nome.Length; discussion
  • 32. Protected and Internal protected internal protected internal protectedinternal discussion
  • 34.
  • 35. Call to action • Use the IDE and language features • Dip your toes in custom diagnostics • Consider forking the compiler source • Give feedback
  • 36. References MSDN – http://www.msdn.com/roslyn Download Preview – http://aka.ms/Roslyn CodePlex – http://roslyn.codeplex.com/ Roslyn source browser – http://source.roslyn.codeplex.com/
  • 37. References The Future of C# - //build/ 2014 – http://channel9.msdn.com/Events/Build/2014/2-577 What’s New for C# Developers - //build/ 2014 – http://channel9.msdn.com/Events/Build/2014/9-020 Anders Hejlsberg Live Q&A - //build/ 2014 – http://channel9.msdn.com/Events/Build/2014/9-010 The Future of Visual Basic and C# - TechEd North America 2014 – http://channel9.msdn.com/Events/TechEd/NorthAmerica/2014/DEV-B336 Channel 9 Live: .NET Framework Q&A - TechEd North America 2014 – http://channel9.msdn.com/Events/TechEd/NorthAmerica/2014/C9-22
  • 38. References C# – Novas Funcionalidades do C# 6.0 – Antevisão de Abril de 2014 – http://www.revista-programar.info/artigos/c-novas-funcionalidades-do-c-6-0-antevisao-de-abril- de-2014/ A C# 6.0 Language Preview – http://msdn.microsoft.com/en-us/magazine/dn683793.aspx
  • 41. Patrocinadores “GOLD” Twitter: @PTMicrosoft http://www.microsoft.com/portugal
  • 44. http://bit.ly/netponto-aval-47 * Para quem não puder preencher durante a reunião, iremos enviar um email com o link à tarde
  • 45. Próximas reuniões presenciais 31/05/2014 – Maio (Lisboa) 21/06/2014 – Junho (Lisboa) 27/07/2014 – Julho (Lisboa) ??/??/???? – ????? (Porto) Reserva estes dias na agenda! :)

Hinweis der Redaktion

  1. Para quem puder ir preenchendo, assim não chateio mais logo  É importante para recebermos nós feedback, e para darmos feedback aos nossos oradores http://goqr.me/