SlideShare una empresa de Scribd logo
1 de 48
JavaScript SQL Java C# Python PHP C++ C TypeScript
Rust Smalltalk TypeScript Swift Go Python Elixir C# Scala
Python JavaScript Go C++ Java TypeScript C# Swift Ruby
Bound together by:
• TypeScript
• Visual Studio Code
• SQL Technologies
January 2002
•C# 1.0
•Framework 1.0
•VS 2002
April 2003
•C# 1.2
•Framework 1.1
•VS 2003
November 2005
•C# 2.0
•Framework 2.0
•VS 2005
November 2007
•C# 3.0
•Framework 2.0 – 3.5
•VS 2008 & 2010
April 2010
•C# 4.0
•Framework 4.0
•VS 2010
August 2012
•C# 5.0
•Framework 4.5
•VS 2010
July 2015
•C# 6.0
•Framework 4.6
•VS 2015
March 2017
•C# 7.0
•Framework 4.6.2
•VS 2017
August 2017
•C# 7.1
•Framework 4.6.2
•VS 2017 15.3
November 2017
•C# 7.2
•Framework 4.7.1
•VS 2017 15.5
May 2018
•C# 7.3
•Framework 4.7.2
•VS 2017 15.7
using static System.Console;
using static System.String;
namespace UsingStaticDirective
{
class Program
{
static void Main(string[] args)
{
int ndx = 0;
foreach (string arg in args)
WriteLine(Format("Argument {0} = {1}", ndx++, arg));
ReadLine();
}
}
}
int triesRemaining = 2;
do
{
try
{
DoSomething();
}
catch (ServiceUnavailableException ex) when (ex.ReasonCode == 113)
{
--triesRemaining;
}
} while (triesRemaining > 0);
This feature isn’t just syntactical sugar. It’s been in the CLR from the beginning.
class Student
{
public bool Enrolled { get; private set; } = false;
public List<Course> Courses { get; private set; } =
new List<Course>
{
new Course()
{
Name = "Orientation”
}
};
}
public class Student
{
public string FirstName { get; set; }
public string LastName { get; set; }
public override string ToString() => String.Format(
"{1}, {0}", FirstName, LastName);
}
static string Greeting(Student s)
{
return String.Format("Hello {0} {1}:",
s.FirstName, s.LastName);
}
static string Greeting(Student s)
{
return String.Format("Hello {0} {1}:",
s?.FirstName ?? "Unknown", s?.LastName ?? "Unknown");
}
static string FirstStudentGreeting(Student[] students)
{
return Greeting(students[0]);
}
static string FirstStudentGreeting(Student[] students)
{
return Greeting(students?[0]);
}
static string AlternateGreeting(Student s)
{
if (s?.FirstName?.StartsWith("K") ?? false)
return String.Format("Howdy {0},", s?.FirstName?.ToUpper());
return Greeting(s);
}
public class Student
{
public string FirstName { get; set; }
public string LastName { get; set; }
public List<float> Grades { get; } = new List<float>();
public float GPA => Grades.Average();
public override string ToString() =>
$"{FirstName} {LastName.ToUpper()} : {GPA:F2}";
public string AllGrades() =>
$@"All Grades: {Grades.OrderByDescending(g => g)
.Select(s => s.ToString("F2"))
.Aggregate((partial, element) => $"{partial}, {element}")}";
}
public void RegexFormat(string source, int min, int max, string regEx)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (min < 0)
throw new ArgumentOutOfRangeException(nameof(min));
if (max > 100)
throw new ArgumentOutOfRangeException(nameof(max));
if (regEx == null)
throw new ArgumentNullException(nameof(regEx));
if (regEx.Trim().Length == 0)
throw new ArgumentException("May not be empty.", nameof(regEx));
// ...
}
var httpStatuses = new Dictionary<ushort, string>
{
[200] = "OK",
[201] = "Created",
[202] = "Accepted",
[301] = "Moved Permanently",
[302] = "Found",
[400] = "Bad Request",
[401] = "Unauthorized",
[403] = "Forbidden",
[404] = "Not Found",
[429] = "Too Many Requests",
[500] = "Internal Server Error"
};
Console.WriteLine($"HTTP 500 = {httpStatuses[500]}");
int n1 = 0b0000_0000_1111_1111_0000_0000_1111_1111;
int x1 = 0x00_FF_00_FF;
int n2 = 0b0110_1101_0011_1101_1011_1100_0101_1001;
int x2 = 0x6D_3D_BC_59;
// This one won't compile
// int n3 = 0b11101101001111011011110001011001;
Console.WriteLine($"{n1:X} = {x1:X}");
Console.WriteLine($"{n2:X} = {x2:X}");
Console.Write("Watermelons are delicious. True or false? ");
string input = Console.ReadLine();
if (Boolean.TryParse(input, out bool answer))
Console.WriteLine(answer ? "Good answer." : "WRONG!");
else
Console.WriteLine("You're mumbling.");
Console.WriteLine($"I can still see your answer ({answer}) out here.");
(string, int, double) parts = ("a", 2, 3.1415927d);
// outputs System.ValueTuple`3
Console.WriteLine(parts.GetType().Name);
Console.WriteLine($@"{parts.Item1}={parts.Item1.GetType().Name}
{parts.Item2}={parts.Item2.GetType().Name}
{parts.Item3}={parts.Item3.GetType().Name}");
var (name, score, ratio) = ("b", 0b10, Math.PI);
Console.WriteLine($@"{name}={name.GetType().Name}
{score}={score.GetType().Name}
{ratio}={ratio.GetType().Name}");
private static (int Max, int Min) Range(IEnumerable<int> numbers) {
int min = int.MaxValue;
int max = int.MinValue;
foreach (var n in numbers) {
min = (n < min) ? n : min;
max = (n > max) ? n : max;
}
return (max, min);
}
List<int> numbers = new List<int>();
Random rng = new Random(DateTime.UtcNow.Millisecond);
for (int ndx = 0; ndx < 10; ndx++)
numbers.Add(rng.Next(0, 1000));
(int max, int min) = Range(numbers);
Console.WriteLine($"min = {min}, max = {max}");
public static (float Temperature, float Humidity, float WindDirection,
float WindSpeed, float BarometricPressure, float Visibility)
GetWeatherData(float latitude, float longitude)
{
// ...
}
var (temperatura, humedad, _, _, _, visibilidad) =
GetWeatherData(37.662545f, -77.575714f);
public class Person {
public string FirstName { get; set; }
public string LastName { get; set; }
public string City { get; set; }
public void Deconstruct(out string fname,
out string lname, out string city) {
fname = FirstName;
lname = LastName;
city = City;
}
}
Person p = new Person() { FirstName = "Willy",
LastName = "Hughes", City = "Greenville" };
var (first, _, city) = p;
Console.WriteLine($"Welcome {first} of {city}!");
// CONST PATTERN
if (o is null) throw new ArgumentNullException(nameof(o));
if (o is 42) Console.WriteLine("it's 42");
// TYPE PATTERN
if (o is int i) Console.WriteLine($"int = {i}");
if (o is Person p) Console.WriteLine($"person = {p.FirstName}");
// VAR PATTERN
if (o is var x) Console.WriteLine($"{x?.GetType()?.Name}");
switch (o)
{
case null:
throw new ArgumentNullException(nameof(o));
case 42:
Console.WriteLine("it's 42");
case int i:
Console.WriteLine($"int = {i}");
case Person p:
Console.WriteLine($"person = {p.FirstName}");
case var x:
Console.WriteLine($"{x?.GetType()?.Name}");
}
static ref T Find<T>(T[] coll, Func<T, bool> matches) {
for (int ndx = 0; ndx < coll.GetLength(0); ndx++) {
if (matches(coll[ndx]))
return ref coll[ndx];
}
throw new ApplicationException("Not found.");
}
int[] numbers = new int[10];
Random rng = new Random(DateTime.UtcNow.Millisecond);
for (int ndx = 0; ndx < numbers.GetLength(0); ndx++)
numbers[ndx] = rng.Next(0, 10);
Dump(numbers);
ref var x = ref Find(numbers, n => n > 5);
x = -1;
Dump(numbers);
public static IEnumerable<string> ReadLineByLine(string fileName)
{
if (string.IsNullOrEmpty(fileName))
throw new ArgumentNullException(nameof(fileName));
foreach (var line in File.ReadAllLines(fileName))
yield return line;
}
001: string fileName = null;
002: var query = ReadLineByLineLocal(fileName)
.Select(x => $"t{x}")
.Where(l => l.Length > 10);
003: string first = query.First();
public static IEnumerable<string> ReadLineByLineLocal(string fileName)
{
if (string.IsNullOrEmpty(fileName))
throw new ArgumentNullException(nameof(fileName));
return ReadLineByLineImpl();
IEnumerable<string> ReadLineByLineImpl()
{
foreach (var line in File.ReadAllLines(fileName))
yield return line;
}
}
public class Identifier
{
private string label = String.Empty;
public string Label
{
get => label;
set => label = value ?? "empty";
}
}
public string Name
{
get => name;
set => name = value ??
throw new ArgumentNullException(nameof(value),
"New name must not be null");
}
public async ValueTask<int> Func()
{
await Task.Delay(100);
return 5;
}
static int Main()
{
return DoAsyncWork().GetAwaiter().GetResult();
}
static async Task<int> Main()
{
return await DoAsyncWork();
}
Func<string, bool> whereClause = default(Func<string, bool>);
Func<string, bool> whereClause = default;
int count = 5;
string label = "Colors used in the map";
var pair = (count: count, label: label);
int count = 5;
string label = "Colors used in the map";
var pair = (count, label);
• New “in” keyword
• Like ref and out
• Guarantees that the value will not be modified
• Returns of “ref readonly”
• Creates a defensive copy of the result
• Enforces read only semantics at compile time
• New “readonly struct” typing
• Immutable value types
• Allows read only references everywhere
• Removes the need for defensive copies
• New “ref struct” typing
• Forces allocation on the stack, never on the heap
• Used as the basis for Span<T>
• New “readonly ref struct” combines the qualities of
“readonly struct” and “ref struct”
DoSomething(age: 25, ”Angela”);
int binaryValue = 0b_0101_0101;
• public
• private
• protected
• internal
• protected internal
private protected - Access is limited to the containing class or
types derived from the containing class within the current assembly.
public class UsingDelegate<T> where T : System.Delegate { }
public class Multicaster<T> where T : System.MulticastDelegate { }
public static Dictionary<int, string> EnumNamedValues<T>()
where T : System.Enum
{
var result = new Dictionary<int, string>();
var values = Enum.GetValues(typeof(T));
foreach (int item in values)
result.Add(item, Enum.GetName(typeof(T), item));
return result;
}
var left = (a: 5, b: 10);
var right = (a: 5, b: 10);
(int a, int b)? nullableTuple = right;
(int? a, int? b) nullableMembers = (5, 10);
(long a, long b) longTuple = (5, 10);
Console.WriteLine(left == right); // true
Console.WriteLine(left == nullableTuple); // true
Console.WriteLine(left == nullableMembers); // true
Console.WriteLine(left == longTuple); // true
[field: SomeThingAboutFieldAttribute]
public int SomeProperty { get; set; }
https://github.com/dotnet/csharplang/tree/master/proposals
Sir Tony Hoare, 2009
string text1 = null; // Cannot convert null to non-nullable reference
string? text2 = null;
string text3 = text2; // Possible null reference assignment
Console.WriteLine( text2.Length ); // Possible dereference of a null
https://github.com/dotnet/csharplang/blob/master/proposals/nullable-reference-types.md
public extension IntExtension extends int
{
public bool Even => this % 2 == 0;
}
int x = int.Parse(Console.Readline());
if (x.Even)
{
Console.WriteLine(“You’ve typed an even number.”);
}
interface IDisplayService
{
void DisplayMessage(string message) { WriteLine(message); }
}
https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md

Más contenido relacionado

La actualidad más candente

Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
Talbott Crowell
 
Declarative authorization in REST services in SharePoint with F# and ServiceS...
Declarative authorization in REST services in SharePoint with F# and ServiceS...Declarative authorization in REST services in SharePoint with F# and ServiceS...
Declarative authorization in REST services in SharePoint with F# and ServiceS...
Sergey Tihon
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
Sang Don Kim
 

La actualidad más candente (20)

Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 
Roslyn
RoslynRoslyn
Roslyn
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
GOCON Autumn (Story of our own Monitoring Agent in golang)
GOCON Autumn (Story of our own Monitoring Agent in golang)GOCON Autumn (Story of our own Monitoring Agent in golang)
GOCON Autumn (Story of our own Monitoring Agent in golang)
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
 
Go Language Hands-on Workshop Material
Go Language Hands-on Workshop MaterialGo Language Hands-on Workshop Material
Go Language Hands-on Workshop Material
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
 
Dove sono i tuoi vertici e di cosa stanno parlando?
Dove sono i tuoi vertici e di cosa stanno parlando?Dove sono i tuoi vertici e di cosa stanno parlando?
Dove sono i tuoi vertici e di cosa stanno parlando?
 
Introduction to Go language
Introduction to Go languageIntroduction to Go language
Introduction to Go language
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
Declarative authorization in REST services in SharePoint with F# and ServiceS...
Declarative authorization in REST services in SharePoint with F# and ServiceS...Declarative authorization in REST services in SharePoint with F# and ServiceS...
Declarative authorization in REST services in SharePoint with F# and ServiceS...
 
GO programming language
GO programming languageGO programming language
GO programming language
 
Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016Static Analysis of PHP Code – IPC Berlin 2016
Static Analysis of PHP Code – IPC Berlin 2016
 
Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)
 
Core Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th MayCore Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th May
 
Hack and HHVM
Hack and HHVMHack and HHVM
Hack and HHVM
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
Hack Programming Language
Hack Programming LanguageHack Programming Language
Hack Programming Language
 
PHP Technical Question
PHP Technical QuestionPHP Technical Question
PHP Technical Question
 

Similar a C# 6 and 7 and Futures 20180607

AST Transformations
AST TransformationsAST Transformations
AST Transformations
HamletDRC
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 

Similar a C# 6 and 7 and Futures 20180607 (20)

Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
.NET Foundation, Future of .NET and C#
.NET Foundation, Future of .NET and C#.NET Foundation, Future of .NET and C#
.NET Foundation, Future of .NET and C#
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
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
 
Python crush course
Python crush coursePython crush course
Python crush course
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
 
Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 
Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016Kotlin Austin Droids April 14 2016
Kotlin Austin Droids April 14 2016
 
C# 7
C# 7C# 7
C# 7
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 

Más de Kevin Hazzard

What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#
Kevin Hazzard
 
Better contracts better code - august 2010
Better contracts   better code - august 2010Better contracts   better code - august 2010
Better contracts better code - august 2010
Kevin Hazzard
 

Más de Kevin Hazzard (7)

Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
 
What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#What the math geeks don't want you to know about F#
What the math geeks don't want you to know about F#
 
Better contracts better code - august 2010
Better contracts   better code - august 2010Better contracts   better code - august 2010
Better contracts better code - august 2010
 
Introduction to SQL Azure
Introduction to SQL AzureIntroduction to SQL Azure
Introduction to SQL Azure
 
Enterprise Data Validation
Enterprise Data ValidationEnterprise Data Validation
Enterprise Data Validation
 
Dynamic Language Performance
Dynamic Language PerformanceDynamic Language Performance
Dynamic Language Performance
 

Último

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Último (20)

%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 

C# 6 and 7 and Futures 20180607

  • 1.
  • 2. JavaScript SQL Java C# Python PHP C++ C TypeScript
  • 3. Rust Smalltalk TypeScript Swift Go Python Elixir C# Scala
  • 4. Python JavaScript Go C++ Java TypeScript C# Swift Ruby
  • 5. Bound together by: • TypeScript • Visual Studio Code • SQL Technologies
  • 6. January 2002 •C# 1.0 •Framework 1.0 •VS 2002 April 2003 •C# 1.2 •Framework 1.1 •VS 2003 November 2005 •C# 2.0 •Framework 2.0 •VS 2005 November 2007 •C# 3.0 •Framework 2.0 – 3.5 •VS 2008 & 2010 April 2010 •C# 4.0 •Framework 4.0 •VS 2010 August 2012 •C# 5.0 •Framework 4.5 •VS 2010 July 2015 •C# 6.0 •Framework 4.6 •VS 2015 March 2017 •C# 7.0 •Framework 4.6.2 •VS 2017 August 2017 •C# 7.1 •Framework 4.6.2 •VS 2017 15.3 November 2017 •C# 7.2 •Framework 4.7.1 •VS 2017 15.5 May 2018 •C# 7.3 •Framework 4.7.2 •VS 2017 15.7
  • 7.
  • 8. using static System.Console; using static System.String; namespace UsingStaticDirective { class Program { static void Main(string[] args) { int ndx = 0; foreach (string arg in args) WriteLine(Format("Argument {0} = {1}", ndx++, arg)); ReadLine(); } } }
  • 9. int triesRemaining = 2; do { try { DoSomething(); } catch (ServiceUnavailableException ex) when (ex.ReasonCode == 113) { --triesRemaining; } } while (triesRemaining > 0); This feature isn’t just syntactical sugar. It’s been in the CLR from the beginning.
  • 10. class Student { public bool Enrolled { get; private set; } = false; public List<Course> Courses { get; private set; } = new List<Course> { new Course() { Name = "Orientation” } }; }
  • 11. public class Student { public string FirstName { get; set; } public string LastName { get; set; } public override string ToString() => String.Format( "{1}, {0}", FirstName, LastName); }
  • 12. static string Greeting(Student s) { return String.Format("Hello {0} {1}:", s.FirstName, s.LastName); } static string Greeting(Student s) { return String.Format("Hello {0} {1}:", s?.FirstName ?? "Unknown", s?.LastName ?? "Unknown"); } static string FirstStudentGreeting(Student[] students) { return Greeting(students[0]); } static string FirstStudentGreeting(Student[] students) { return Greeting(students?[0]); } static string AlternateGreeting(Student s) { if (s?.FirstName?.StartsWith("K") ?? false) return String.Format("Howdy {0},", s?.FirstName?.ToUpper()); return Greeting(s); }
  • 13. public class Student { public string FirstName { get; set; } public string LastName { get; set; } public List<float> Grades { get; } = new List<float>(); public float GPA => Grades.Average(); public override string ToString() => $"{FirstName} {LastName.ToUpper()} : {GPA:F2}"; public string AllGrades() => $@"All Grades: {Grades.OrderByDescending(g => g) .Select(s => s.ToString("F2")) .Aggregate((partial, element) => $"{partial}, {element}")}"; }
  • 14. public void RegexFormat(string source, int min, int max, string regEx) { if (source == null) throw new ArgumentNullException(nameof(source)); if (min < 0) throw new ArgumentOutOfRangeException(nameof(min)); if (max > 100) throw new ArgumentOutOfRangeException(nameof(max)); if (regEx == null) throw new ArgumentNullException(nameof(regEx)); if (regEx.Trim().Length == 0) throw new ArgumentException("May not be empty.", nameof(regEx)); // ... }
  • 15. var httpStatuses = new Dictionary<ushort, string> { [200] = "OK", [201] = "Created", [202] = "Accepted", [301] = "Moved Permanently", [302] = "Found", [400] = "Bad Request", [401] = "Unauthorized", [403] = "Forbidden", [404] = "Not Found", [429] = "Too Many Requests", [500] = "Internal Server Error" }; Console.WriteLine($"HTTP 500 = {httpStatuses[500]}");
  • 16.
  • 17. int n1 = 0b0000_0000_1111_1111_0000_0000_1111_1111; int x1 = 0x00_FF_00_FF; int n2 = 0b0110_1101_0011_1101_1011_1100_0101_1001; int x2 = 0x6D_3D_BC_59; // This one won't compile // int n3 = 0b11101101001111011011110001011001; Console.WriteLine($"{n1:X} = {x1:X}"); Console.WriteLine($"{n2:X} = {x2:X}");
  • 18. Console.Write("Watermelons are delicious. True or false? "); string input = Console.ReadLine(); if (Boolean.TryParse(input, out bool answer)) Console.WriteLine(answer ? "Good answer." : "WRONG!"); else Console.WriteLine("You're mumbling."); Console.WriteLine($"I can still see your answer ({answer}) out here.");
  • 19. (string, int, double) parts = ("a", 2, 3.1415927d); // outputs System.ValueTuple`3 Console.WriteLine(parts.GetType().Name); Console.WriteLine($@"{parts.Item1}={parts.Item1.GetType().Name} {parts.Item2}={parts.Item2.GetType().Name} {parts.Item3}={parts.Item3.GetType().Name}");
  • 20. var (name, score, ratio) = ("b", 0b10, Math.PI); Console.WriteLine($@"{name}={name.GetType().Name} {score}={score.GetType().Name} {ratio}={ratio.GetType().Name}");
  • 21. private static (int Max, int Min) Range(IEnumerable<int> numbers) { int min = int.MaxValue; int max = int.MinValue; foreach (var n in numbers) { min = (n < min) ? n : min; max = (n > max) ? n : max; } return (max, min); } List<int> numbers = new List<int>(); Random rng = new Random(DateTime.UtcNow.Millisecond); for (int ndx = 0; ndx < 10; ndx++) numbers.Add(rng.Next(0, 1000)); (int max, int min) = Range(numbers); Console.WriteLine($"min = {min}, max = {max}");
  • 22. public static (float Temperature, float Humidity, float WindDirection, float WindSpeed, float BarometricPressure, float Visibility) GetWeatherData(float latitude, float longitude) { // ... } var (temperatura, humedad, _, _, _, visibilidad) = GetWeatherData(37.662545f, -77.575714f);
  • 23. public class Person { public string FirstName { get; set; } public string LastName { get; set; } public string City { get; set; } public void Deconstruct(out string fname, out string lname, out string city) { fname = FirstName; lname = LastName; city = City; } } Person p = new Person() { FirstName = "Willy", LastName = "Hughes", City = "Greenville" }; var (first, _, city) = p; Console.WriteLine($"Welcome {first} of {city}!");
  • 24. // CONST PATTERN if (o is null) throw new ArgumentNullException(nameof(o)); if (o is 42) Console.WriteLine("it's 42"); // TYPE PATTERN if (o is int i) Console.WriteLine($"int = {i}"); if (o is Person p) Console.WriteLine($"person = {p.FirstName}"); // VAR PATTERN if (o is var x) Console.WriteLine($"{x?.GetType()?.Name}");
  • 25. switch (o) { case null: throw new ArgumentNullException(nameof(o)); case 42: Console.WriteLine("it's 42"); case int i: Console.WriteLine($"int = {i}"); case Person p: Console.WriteLine($"person = {p.FirstName}"); case var x: Console.WriteLine($"{x?.GetType()?.Name}"); }
  • 26. static ref T Find<T>(T[] coll, Func<T, bool> matches) { for (int ndx = 0; ndx < coll.GetLength(0); ndx++) { if (matches(coll[ndx])) return ref coll[ndx]; } throw new ApplicationException("Not found."); } int[] numbers = new int[10]; Random rng = new Random(DateTime.UtcNow.Millisecond); for (int ndx = 0; ndx < numbers.GetLength(0); ndx++) numbers[ndx] = rng.Next(0, 10); Dump(numbers); ref var x = ref Find(numbers, n => n > 5); x = -1; Dump(numbers);
  • 27. public static IEnumerable<string> ReadLineByLine(string fileName) { if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException(nameof(fileName)); foreach (var line in File.ReadAllLines(fileName)) yield return line; } 001: string fileName = null; 002: var query = ReadLineByLineLocal(fileName) .Select(x => $"t{x}") .Where(l => l.Length > 10); 003: string first = query.First(); public static IEnumerable<string> ReadLineByLineLocal(string fileName) { if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException(nameof(fileName)); return ReadLineByLineImpl(); IEnumerable<string> ReadLineByLineImpl() { foreach (var line in File.ReadAllLines(fileName)) yield return line; } }
  • 28. public class Identifier { private string label = String.Empty; public string Label { get => label; set => label = value ?? "empty"; } }
  • 29. public string Name { get => name; set => name = value ?? throw new ArgumentNullException(nameof(value), "New name must not be null"); }
  • 30. public async ValueTask<int> Func() { await Task.Delay(100); return 5; }
  • 31.
  • 32. static int Main() { return DoAsyncWork().GetAwaiter().GetResult(); } static async Task<int> Main() { return await DoAsyncWork(); }
  • 33. Func<string, bool> whereClause = default(Func<string, bool>); Func<string, bool> whereClause = default;
  • 34. int count = 5; string label = "Colors used in the map"; var pair = (count: count, label: label); int count = 5; string label = "Colors used in the map"; var pair = (count, label);
  • 35.
  • 36. • New “in” keyword • Like ref and out • Guarantees that the value will not be modified • Returns of “ref readonly” • Creates a defensive copy of the result • Enforces read only semantics at compile time • New “readonly struct” typing • Immutable value types • Allows read only references everywhere • Removes the need for defensive copies • New “ref struct” typing • Forces allocation on the stack, never on the heap • Used as the basis for Span<T> • New “readonly ref struct” combines the qualities of “readonly struct” and “ref struct”
  • 38. int binaryValue = 0b_0101_0101;
  • 39. • public • private • protected • internal • protected internal private protected - Access is limited to the containing class or types derived from the containing class within the current assembly.
  • 40.
  • 41. public class UsingDelegate<T> where T : System.Delegate { } public class Multicaster<T> where T : System.MulticastDelegate { } public static Dictionary<int, string> EnumNamedValues<T>() where T : System.Enum { var result = new Dictionary<int, string>(); var values = Enum.GetValues(typeof(T)); foreach (int item in values) result.Add(item, Enum.GetName(typeof(T), item)); return result; }
  • 42. var left = (a: 5, b: 10); var right = (a: 5, b: 10); (int a, int b)? nullableTuple = right; (int? a, int? b) nullableMembers = (5, 10); (long a, long b) longTuple = (5, 10); Console.WriteLine(left == right); // true Console.WriteLine(left == nullableTuple); // true Console.WriteLine(left == nullableMembers); // true Console.WriteLine(left == longTuple); // true
  • 46. string text1 = null; // Cannot convert null to non-nullable reference string? text2 = null; string text3 = text2; // Possible null reference assignment Console.WriteLine( text2.Length ); // Possible dereference of a null https://github.com/dotnet/csharplang/blob/master/proposals/nullable-reference-types.md
  • 47. public extension IntExtension extends int { public bool Even => this % 2 == 0; } int x = int.Parse(Console.Readline()); if (x.Even) { Console.WriteLine(“You’ve typed an even number.”); }
  • 48. interface IDisplayService { void DisplayMessage(string message) { WriteLine(message); } } https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md