SlideShare uma empresa Scribd logo
1 de 84
Edição 2018
#mvpconf
Giovanni Bassi
Visual Studio/C#
C# 7 ao 8
#mvpconf
Patrocínio:
#mvpconf
Beneficiários do Evento:
APAE-Associação de Pais e Amigos dos
Excepcionais
Lar da Criança Ninho de Paz
Para quem quiser doar outros valores além das inscrições:
CAIXA ECONÔMICA FEDERAL
AG: 0504
CC: 01823-0
CNPJ: 89.078.059/0001-06
ITAU UNIBANCO AS
Agência: 467
CC: 611109
CNPJ 53.372.454/0001-50
#mvpconf
Giovanni Bassi
Categorias de premiação:
Visual Studio/C#
Primeiro ano premiado:
2009
Número de prêmios MVPs:
9
/GBassi
/giggio.tech
/giggiobassi
@giovannibassi
Biografia
Programador, Microsoft MVP, Não gerente
blog.lambda3.com.br, podcast.lambda3.com.br, dotnetarchitects.net, nodebr, dockersp
Escalador e ciclista
blog.lambda3.com.br
podcast.lambda3.com.br
podcast.lambda3.com.br
0 – Eventos
1 – Docker
2 – .NET Core RC2
3 – Git
4 – Estudo
5 – Open Source
6 – Xamarin
7 – Node.js
8 – Democracia organizacional
9 – O programador poliglota
...
Toda semana em:
Acreditamos que a diversidade, em
suas diversas expressões, deve ser
respeitada e valorizada, e que uma
sociedade mais diversa é uma
sociedade melhor.
diversidade.tech
vagas.lambda3.com.br
Giovanni Bassi
• Programador
• Microsoft MVP
• Não gerente
• blog.lambda3.com.br, podcast.lambda3.com.br,
dotnetarchitects.net, nodebr, dockersp
@giovannibassi
/giggio.tech
• Escalador e ciclista
podcast.lambda3.com.br
0 – Eventos
1 – Docker
2 – .NET Core RC2
3 – Git
4 – Estudo
5 – Open Source
6 – Xamarin
7 – Node.js
8 – Democracia organizacional
9 – O programador poliglota
...
Toda semana em:
Acreditamos que a diversidade, em
suas diversas expressões, deve ser
respeitada e valorizada, e que uma
sociedade mais diversa é uma
sociedade melhor.
diversidade.tech
vagas.lambda3.com.br
bit.ly/novidadescsharp7
Evolução do C#
Código gerenciado
Generics
Language Integrated Query
Dinamismo + paridade nas linguagens
C# 5 + VB 11
Programação assíncrona
C# 1 + VB 7
C# 2 + VB 8
C# 3 + VB 9
C# 4 + VB 10
C# 6 + VB 14
Roslyn
Código gerenciado
Generics
Language Integrated Query
Dinamismo + paridade nas linguagens
C# 5 + VB 11
Programação assíncrona
C# 1 + VB 7
C# 2 + VB 8
C# 3 + VB 9
C# 4 + VB 10
C# 6 + VB 14
Roslyn
C# 7 + VB 15
Features!
Código gerenciado
Generics
Language Integrated Query
Dinamismo + paridade nas linguagens
C# 5 + VB 11
Programação assíncrona
C# 1 + VB 7
C# 2 + VB 8
C# 3 + VB 9
C# 4 + VB 10
C# 6 + VB 14
Roslyn
C# 7 + VB 15
Features! Features! Features!Features!
Código gerenciado
Generics
Language Integrated Query
Dinamismo + paridade nas linguagens
C# 5 + VB 11
Programação assíncrona
C# 1 + VB 7
C# 2 + VB 8
C# 3 + VB 9
C# 4 + VB 10
C# 6 + VB 14
Roslyn
C# 7 + VB 15
Features! Features! Features!
Features (parte 2)?
C# 8 + VB 16?
https://insights.stackoverflow.com/survey/2018/#most-popular-technologies
https://insights.stackoverflow.com/survey/2018/#most-popular-technologies
F#
10,000’s
Tens of thousands
VB
100,000’s
Hundreds of thousands
C#
1,000,000’s
Millions
System.ValueTuple
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
C# 7.0
public static int DiceSum(IEnumerable<object> values)
{
var sum = 0;
foreach (var item in values)
{
if (item is int val)
sum += val;
else if (item is IEnumerable<object> subList)
sum += DiceSum(subList);
}
return sum;
}
https://docs.microsoft.com/dotnet/csharp/pattern-matching
http://bit.ly/cspatternmatching
https://docs.microsoft.com/dotnet/csharp/pattern-matching
public static int DiceSum(IEnumerable<object> values)
{
var sum = 0;
foreach (var item in values)
{
switch (item)
{
}
}
return sum;
}
http://bit.ly/cspatternmatching
case 0:
break;
case int val:
sum += val;
break;
case PercentileDie die:
sum += die.Multiplier * die.Value;
break;
https://docs.microsoft.com/dotnet/csharp/pattern-matching
public static int DiceSum(IEnumerable<object> values)
{
var sum = 0;
foreach (var item in values)
{
switch (item)
{
}
}
return sum;
}
http://bit.ly/cspatternmatching
case 0:
break;
case int val:
sum += val;
break;
case PercentileDie die:
sum += die.Multiplier * die.Value;
break;
https://docs.microsoft.com/dotnet/csharp/pattern-matching
case IEnumerable<object> subList when subList.Any():
sum += DiceSum(subList);
break;
case IEnumerable<object> subList:
break;
case null:
break;
default:
throw new InvalidOperationException("unknown");
public static int DiceSum(IEnumerable<object> values)
{
var sum = 0;
foreach (var item in values)
{
switch (item)
{
}
}
return sum;
}
http://bit.ly/cspatternmatching
var numbers1 = (1, 2);
var objs = ("1", 2);
WriteLine($"{numbers1.Item1}, {numbers1.Item2}");
(int one, int two) numbers2 = (1, 2);
WriteLine($"{numbers2.Item1}, {numbers2.Item2}");
WriteLine($"{numbers2.one}, {numbers2.two}");
var numbers3 = (one: 1, two: 2);
WriteLine($"{numbers3.one}, {numbers3.two}");
(int uno, int due) numbers4 = (one: 1, two: 2);
WriteLine($"{numbers4.uno}, {numbers4.due}");
// WriteLine($"{numbers4.one}, {numbers4.two}"); // error
https://docs.microsoft.com/dotnet/csharp/tuples
http://bit.ly/cstuplas
void M()
{
var (name, company) = Person.Get();
WriteLine($"{name}, {company}");
}
class Person
{
public string Name { get; set; }
public string Company { get; set; }
public void Deconstruct(out string name, out string company)
{
name = Name;
company = Company;
}
public static Person Get() => new Person { Name = "…", Company = "…" };
} https://docs.microsoft.com/dotnet/csharp/tupleshttp://bit.ly/cstuplas
var numbers = (one: 1, two: 2);
var (uno, due) = numbers;
WriteLine($"{uno}, {due}");
https://docs.microsoft.com/dotnet/csharp/tuples
http://bit.ly/cstuplas
if (int.TryParse("1", out int result))
WriteLine(result);
if (int.TryParse("1", out var result2))
WriteLine(result2);
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#out-variables
http://bit.ly/csoutvars
(int x, int y) GetCoordinates() => (1, 2);
var (_, y) = GetCoordinates();
https://docs.microsoft.com/dotnet/csharp/discards
http://bit.ly/csdiscards
void ObjectDeconstruction()
{
var (name, _) = Person.Get();
}
https://docs.microsoft.com/dotnet/csharp/discards
http://bit.ly/csdiscards
if (int.TryParse("1", out _))
WriteLine("It is a number!");
https://docs.microsoft.com/dotnet/csharp/discards
http://bit.ly/csdiscards
object o = 1;
if (o is Person p)
WriteLine(p.Company);
else if (o is null)
WriteLine("null");
else if (o is var _)
WriteLine("Unknown");
https://docs.microsoft.com/dotnet/csharp/discards
http://bit.ly/csdiscards
ref int Find(int[,] matrix, Func<int, bool> predicate)
{
for (int i = 0; i < matrix.GetLength(0); i++)
for (int j = 0; j < matrix.GetLength(1); j++)
if (predicate(matrix[i, j]))
return ref matrix[i, j];
throw new InvalidOperationException("Not found");
}
void M()
{
var matrix = new [,] { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 42, 10 } };
ref var item = ref Find(matrix, val => val == 42);
WriteLine(item);
item = 24;
WriteLine(matrix[1, 3]);
}
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#ref-locals-and-returns
http://bit.ly/csreflocals
public ExpressionBodiedMembers(string name) => Name = name;
~ExpressionBodiedMembers() => WriteLine("Finalized!");
private string name;
public string Name
{
get => name;
set => name = value;
}
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#more-expression-bodied-members
http://bit.ly/csmaisebm
private string a = GetA() ?? throw new Exception();
private static string GetA() => throw new Exception();
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#throw-expressions
http://bit.ly/csexpthrow
int sixteen = 0b0001_0000;
int thirtyTwo = 0b0010_0000;
int sixtyFour = 0b0100_0000;
int oneHundredTwentyEight = 0b1000_0000;
long oneHundredBillions = 100_000_000_000;
double AvogadroConstant = 6.022_140_857_747_474e23;
decimal GoldenRatio = 1.618_033_988_749M;
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#numeric-literal-syntax-improvements
http://bit.ly/csnumlit
double Average(IEnumerable<int> ns)
{
double Divide(double a, double b)
{
if (b == 0) throw new DivideByZeroException();
return a / b;
}
var sum = ns.Sum();
return Divide(sum, ns.Count());
}
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#local-functions
http://bit.ly/cslocalfunc
void Add1AndSumAll(int[] ms)
{
IEnumerable<int> Sum1(IEnumerable<int> ns)
{
foreach (var n in ns)
yield return n + 1;
}
if (ms == null) throw new NullReferenceException();
WriteLine(Sum1(ms).Sum());
}
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#local-functions
http://bit.ly/cslocalfunc
public async ValueTask<int> Get5()
{
await Task.Delay(100);
return 5;
}
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#generalized-async-return-types
http://bit.ly/csasyncgeneral
public async ValueTask<int> SumAsync(IEnumerable<ValueTask<int>> ns)
{
var sum = 0;
foreach (var nTask in ns)
{
var n = await nTask;
sum += n;
}
return sum;
}
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#generalized-async-return-types
http://bit.ly/csasyncgeneral
C# 7.1
var x = (f1: 1, f2: 2);
var tuple = (x.f1, x.f2, x);
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7-1#inferred-tuple-element-names
http://bit.ly/cstuplainfer
Func<string, bool> predicate = default;
int i = default;
N(default);
https://docs.microsoft.com/dotnet/csharp/programming-guide/statements-expressions-operators/default-value-expressions
http://bit.ly/csliteraldefault
(int, int) N(int[] ns = default) => default;
string O()
{
return default;
}
T P<T>()
{
T t = default;
return t;
}
https://docs.microsoft.com/dotnet/csharp/programming-guide/statements-expressions-operators/default-value-expressions
http://bit.ly/csliteraldefault
static async Task<int> Main(string[] args)
{
await Task.Delay(500);
WriteLine("Done");
return 0;
}
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7-1#async-main
http://bit.ly/csasyncmain
C# 7.2
void M(int i, int j) { }
void N()
{
M(i: 2, 3);
}
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/non-trailing-named-arguments.md
http://bit.ly/csntna
var m = 0b_101; //5
var n = 0x_00C0; // 192
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/leading-separator.md
http://bit.ly/cs_num
class Base
{
private protected int f;
}
class DerivedInSameAssembly : Base
{
void M()
{
var x = base.f;
}
}
class DerivedInOtherAssembly : Base
{
void M()
{
var x = base.f; //error
}
}
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/private-protected.md
http://bit.ly/csprpr
Vector Add(in Vector v1, in Vector v2)
{
v1 = default(Vector); // not OK!!
v1.X = 0; // not OK!!
Foo(ref v1.X); // not OK!!
// OK:
return new Vector(v1.X +v2.X, v1.Y + v2.Y);
}
https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types
http://bit.ly/csmodin
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/readonly-ref.md#refin-extension-methods
public static Ponto Soma(in this Ponto p1, in Ponto p2) =>
new Ponto(p1.X + p2.X, p1.Y + p2.Y);
void In()
{
Ponto p1 = new Ponto(1, 2), p2 = new Ponto(3, 4);
var pResultado = p1.Soma(p2);
var pResultado2 = p1.Soma(new Ponto(3, 4));
var pResultado3 = new Ponto().Soma(new Ponto(3, 4));
}
http://bit.ly/csmodin
public static Ponto Subtrai(ref this Ponto p1, ref Ponto p2) =>
new Ponto(p1.X - p2.X, p1.Y - p2.Y);
void Ref()
{
Ponto p1 = new Ponto(1, 2), p2 = new Ponto(3, 4);
var pResultado = p1.Subtrai(ref p2);
p1.Subtrai(ref new Ponto()); // não compila
new Ponto().Subtrai(ref p1); // não compila
}
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/readonly-ref.md#refin-extension-methods
http://bit.ly/csextref
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/readonly-ref.md#refin-extension-methods
public static void Foo<T>(ref this T p1)
where T : struct
{
}
http://bit.ly/csextref
ref readonly Vector FetchOrigin() => ref origin;
void M()
{
var v1 = new Vector(1, 2, 3);
var v2 = new Vector(4, 5, 6);
var vSum = Add(v1, v2);
ref readonly var origin = ref FetchOrigin();
}
private readonly Vector origin = new Vector(0, 0, 0);
https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types
http://bit.ly/csretrefro
ref readonly var origin = ref FetchOrigin();
var origin2 = FetchOrigin(); // copy created
https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types
http://bit.ly/csretrefro
readonly struct Ponto
{
public Ponto(float x, float y)
{
X = x;
Y = y;
}
public float X { get; }
public float Y { get; }
private readonly static Ponto origem = new Ponto();
public static ref readonly Ponto Origem => ref origem;
}
https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types#readonly-struct-type
http://bit.ly/csrostruct
ref readonly var p = ref Ponto.Origem;
var x = p.X; // sem cópia
https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types#readonly-struct-type
http://bit.ly/csrostruct
ref int M()
{
var arr = new[] { 1, 2, 3 };
var otherArr = new[] { 4, 5, 6 };
ref var r = ref (arr != null ? ref arr[0]: ref
otherArr[0]);
Foo(ref (arr != null ? ref arr[0]: ref otherArr[0]));
(arr != null ? ref arr[0]: ref otherArr[0]) = 1;
return ref (arr != null ? ref arr[0]: ref otherArr[0]);
}
void Foo(ref int i) => i = 42;
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/conditional-ref.md
http://bit.ly/csternarioref
ref struct TwoSpans<T>
{
// pode ter campos desde que não sejam classes
public Span<T> first;
public Span<T> second;
}
// erro: arrays of ref-like types are not allowed.
TwoSpans<int>[] arr = null;
https://docs.microsoft.com/en-us/dotnet/csharp/reference-semantics-with-value-types#ref-struct-type
readonly ref struct ReadOnlyRefPoint2D
{
public int X { get; }
public int Y { get; }
public ReadOnlyRefPoint2D(int x, int y) =>
(X, Y) = (x, y);
}
https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types#readonly-ref-struct-type
C# 7.3
public class Cartesian { public int X { get; } public int Y { get; } }
public class Polar
{
public static bool operator is(Cartesian c, out double R, out double Theta)
{
R = Math.Sqrt(c.X * c.X + c.Y * c.Y);
Theta = Math.Atan2(c.Y, c.X);
return c.X != 0 || c.Y != 0;
}
}
void M()
{
var c = new Cartesian(3, 4);
if (c is Polar(var R, _)) WriteLine(R);
}
https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
public class Bar : Foo
{
private readonly int field1 =
int.TryParse(SomeStatic.Text, out int value) ? value : -1;
public int Value { get; }
public Bar(string text) :
base(int.TryParse(text, out int value))
=> Value = value;
}
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
var query = from text in strings
where int.TryParse(text, out int value)
select value;
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/auto-prop-field-attrs.md
[Serializable]
public class Foo
{
[field: NonSerialized]
public string MySecret { get; set; }
}
C# 8.0
void N(string? aNullableString, bool condition) {
WriteLine(aNullableString.Length); // warning
if (aNullableString != null)
WriteLine(aNullableString); // no warning
if (!string.IsNullOrWhiteSpace(aNullableString))
WriteLine(aNullableString!.Length); // I know better
var anotherNullableString = condition ? "Hello" : aNullableString;
WriteLine(anotherNullableString.Length); // warning
var yetAnotherNullableString = condition ? "Hello" : null;
WriteLine(yetAnotherNullableString.Length); // warning
string nonNullableString = null; //warning
WriteLine(nonNullableString); // no warning
}
https://github.com/dotnet/csharplang/blob/master/proposals/nullable-reference-types.md
https://github.com/dotnet/roslyn/blob/features/NullableReferenceTypes/docs/features/NullableReferenceTypes/README.md
async Task M()
{
foreach await (var i in GetStream())
WriteLine(i);
}
IAsyncEnumerable<int> GetStream() => new[] { 1, 2, 3 }.ToAsyncEnumerable();
async IAsyncEnumerable<int> MyIterator()
{
for (int i = 0; i < 100; i++)
{
await Task.Delay(1000);
yield return i;
}
}
https://github.com/dotnet/csharplang/blob/master/proposals/async-streams.md
using await (IAsyncDisposable resource = await store.GetRecordAsync(…)) { … }
class Foo : IAsyncDisposable
{
public async Task DisposeAsync()
{
await ...
}
}
https://github.com/dotnet/csharplang/blob/master/proposals/async-streams.md
interface I
{
void M() { WriteLine("I.M"); }
}
class C : I { } // OK
void M()
{ I i = new C();
i.M(); // prints "I.M"
}
https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md
class Person : IEquatable<Person>
{
public string First { get; }
public string Last { get; }
public Person(string First, string Last) => (this.First, this.Last) = (First, Last);
public void Deconstruct(out string First, out string Last)
=> (First, Last) = (this.First, this.Last);
public bool Equals(Person other)
=> other != null && First == other.First && Last == other.Last;
public override bool Equals(object obj) => obj is Person other ? Equals(other) : false;
public override int GetHashCode() => GreatHashFunction(First, Last);
…
}
class Person(string First, string Last);
https://github.com/dotnet/csharplang/blob/master/proposals/records.md
extension class Enrollee extends Person
{
// static field
static Dictionary<Person, Professor> enrollees = new Dictionary<Person, Professor>();
// instance method
public void Enroll(Professor supervisor) { enrollees[this] = supervisor; }
// instance property
public Professor Supervisor => enrollees.TryGetValue(this, out var supervisor) ? supervisor : null;
// static property
public static ICollection<Person> Students => enrollees.Keys;
// instance constructor
public Person(string name, Professor supervisor) : this(name) { this.Enroll(supervisor); }
}
https://github.com/dotnet/csharplang/issues/192
#mvpconf
Encerramento:
• Considerações Finais
• Perguntas e Respostas
• Agradecimentos
w w w. l a m b d a 3 . c o m . b r
Obrigado!
Giovanni Bassi

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Infrastructure as Data with Ansible
Infrastructure as Data with AnsibleInfrastructure as Data with Ansible
Infrastructure as Data with Ansible
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
[Nuxeo World 2013] XML EXTENSION POINT COMPLETION IN NUXEO IDE - SUN TAN, SERLI
[Nuxeo World 2013] XML EXTENSION POINT COMPLETION IN NUXEO IDE - SUN TAN, SERLI[Nuxeo World 2013] XML EXTENSION POINT COMPLETION IN NUXEO IDE - SUN TAN, SERLI
[Nuxeo World 2013] XML EXTENSION POINT COMPLETION IN NUXEO IDE - SUN TAN, SERLI
 
Treinamento frontend
Treinamento frontendTreinamento frontend
Treinamento frontend
 
twMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwright
 
PuppetConf 2016: Building Nano Server Images with Puppet and DSC – Michael Sm...
PuppetConf 2016: Building Nano Server Images with Puppet and DSC – Michael Sm...PuppetConf 2016: Building Nano Server Images with Puppet and DSC – Michael Sm...
PuppetConf 2016: Building Nano Server Images with Puppet and DSC – Michael Sm...
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Understanding Non Blocking I/O with Python
Understanding Non Blocking I/O with PythonUnderstanding Non Blocking I/O with Python
Understanding Non Blocking I/O with Python
 
Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7Fundamental of Node.JS - Internship Presentation - Week7
Fundamental of Node.JS - Internship Presentation - Week7
 
Grunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End TierGrunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End Tier
 
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...
PuppetConf 2016: Getting to the Latest Puppet – Nate McCurdy & Elizabeth Witt...
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014
 
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
ZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small Teams
 
Grunt to automate JS build
Grunt to automate JS buildGrunt to automate JS build
Grunt to automate JS build
 
Grunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous IntegrationGrunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous Integration
 

Semelhante a C#7, 7.1, 7.2, 7.3 e C# 8

Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Matteo Collina
 

Semelhante a C#7, 7.1, 7.2, 7.3 e C# 8 (20)

Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
 
Ruby on Rails 3.1: Let's bring the fun back into web programing
Ruby on Rails 3.1: Let's bring the fun back into web programingRuby on Rails 3.1: Let's bring the fun back into web programing
Ruby on Rails 3.1: Let's bring the fun back into web programing
 
.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#
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project Analyzed
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
 
Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3Prototyping w/HTML5 and CSS3
Prototyping w/HTML5 and CSS3
 
Cleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture components
 
C# 6
C# 6C# 6
C# 6
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
Headless Js Testing
Headless Js TestingHeadless Js Testing
Headless Js Testing
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
 
Building a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profitBuilding a Single Page Application using Ember.js ... for fun and profit
Building a Single Page Application using Ember.js ... for fun and profit
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your Code
 

Mais de Giovanni Bassi

Mais de Giovanni Bassi (20)

O que aprendi montando a arquitetura de microsserviços
O que aprendi montando a arquitetura de microsserviçosO que aprendi montando a arquitetura de microsserviços
O que aprendi montando a arquitetura de microsserviços
 
Sendo ágil com git
Sendo ágil com gitSendo ágil com git
Sendo ágil com git
 
Analisando dumps de memória de aplicações .NET
Analisando dumps de memória de aplicações .NETAnalisando dumps de memória de aplicações .NET
Analisando dumps de memória de aplicações .NET
 
Async e await com JavaScript: entenda e use agora
Async e await com JavaScript: entenda e use agoraAsync e await com JavaScript: entenda e use agora
Async e await com JavaScript: entenda e use agora
 
Conhecendo o AKS, o azure container services com kubernetes
Conhecendo o AKS, o azure container services com kubernetesConhecendo o AKS, o azure container services com kubernetes
Conhecendo o AKS, o azure container services com kubernetes
 
Novidades do .NET Core 2.1 e do ASP.NET Core 2.1
Novidades do .NET Core 2.1 e do ASP.NET Core 2.1Novidades do .NET Core 2.1 e do ASP.NET Core 2.1
Novidades do .NET Core 2.1 e do ASP.NET Core 2.1
 
Engenharia ágil de ponta a ponta do clone ao deploy
Engenharia ágil de ponta a ponta do clone ao deployEngenharia ágil de ponta a ponta do clone ao deploy
Engenharia ágil de ponta a ponta do clone ao deploy
 
Entrega contínua fica mais fácil com contêineres
Entrega contínua fica mais fácil com contêineresEntrega contínua fica mais fácil com contêineres
Entrega contínua fica mais fácil com contêineres
 
.NET Core, ASP.NET Core e .NET Standard 2
.NET Core, ASP.NET Core e .NET Standard 2.NET Core, ASP.NET Core e .NET Standard 2
.NET Core, ASP.NET Core e .NET Standard 2
 
.NET com contêineres Windows e Linux
.NET com contêineres Windows e Linux.NET com contêineres Windows e Linux
.NET com contêineres Windows e Linux
 
Async e await com JavaScript: entenda e use agora
Async e await com JavaScript: entenda e use agoraAsync e await com JavaScript: entenda e use agora
Async e await com JavaScript: entenda e use agora
 
Compartilhando código entre frontend e backend com Node.js
Compartilhando código entre frontend e backend com Node.jsCompartilhando código entre frontend e backend com Node.js
Compartilhando código entre frontend e backend com Node.js
 
Construindo uma ferramenta CLI multiplataforma com Node.js
Construindo uma ferramenta CLI multiplataforma com Node.jsConstruindo uma ferramenta CLI multiplataforma com Node.js
Construindo uma ferramenta CLI multiplataforma com Node.js
 
O Futuro do C#: C#8
O Futuro do C#: C#8O Futuro do C#: C#8
O Futuro do C#: C#8
 
Um mergulho nos containers windows
Um mergulho nos containers windowsUm mergulho nos containers windows
Um mergulho nos containers windows
 
Por dentro do .NET Core
Por dentro do .NET CorePor dentro do .NET Core
Por dentro do .NET Core
 
Build e release pipeline com docker
Build e release pipeline com dockerBuild e release pipeline com docker
Build e release pipeline com docker
 
Release contínuo de um microsserviço com Docker ASP.net core e Azure Containe...
Release contínuo de um microsserviço com Docker ASP.net core e Azure Containe...Release contínuo de um microsserviço com Docker ASP.net core e Azure Containe...
Release contínuo de um microsserviço com Docker ASP.net core e Azure Containe...
 
Backend na nuvem com docker
Backend na nuvem com dockerBackend na nuvem com docker
Backend na nuvem com docker
 
Conhecendo, explorando e usando azure container service
Conhecendo, explorando e usando azure container serviceConhecendo, explorando e usando azure container service
Conhecendo, explorando e usando azure container service
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

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...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

C#7, 7.1, 7.2, 7.3 e C# 8

  • 3. #mvpconf Beneficiários do Evento: APAE-Associação de Pais e Amigos dos Excepcionais Lar da Criança Ninho de Paz Para quem quiser doar outros valores além das inscrições: CAIXA ECONÔMICA FEDERAL AG: 0504 CC: 01823-0 CNPJ: 89.078.059/0001-06 ITAU UNIBANCO AS Agência: 467 CC: 611109 CNPJ 53.372.454/0001-50
  • 4. #mvpconf Giovanni Bassi Categorias de premiação: Visual Studio/C# Primeiro ano premiado: 2009 Número de prêmios MVPs: 9 /GBassi /giggio.tech /giggiobassi @giovannibassi Biografia Programador, Microsoft MVP, Não gerente blog.lambda3.com.br, podcast.lambda3.com.br, dotnetarchitects.net, nodebr, dockersp Escalador e ciclista blog.lambda3.com.br podcast.lambda3.com.br
  • 5.
  • 6. podcast.lambda3.com.br 0 – Eventos 1 – Docker 2 – .NET Core RC2 3 – Git 4 – Estudo 5 – Open Source 6 – Xamarin 7 – Node.js 8 – Democracia organizacional 9 – O programador poliglota ... Toda semana em:
  • 7.
  • 8. Acreditamos que a diversidade, em suas diversas expressões, deve ser respeitada e valorizada, e que uma sociedade mais diversa é uma sociedade melhor. diversidade.tech
  • 10. Giovanni Bassi • Programador • Microsoft MVP • Não gerente • blog.lambda3.com.br, podcast.lambda3.com.br, dotnetarchitects.net, nodebr, dockersp @giovannibassi /giggio.tech • Escalador e ciclista
  • 11.
  • 12. podcast.lambda3.com.br 0 – Eventos 1 – Docker 2 – .NET Core RC2 3 – Git 4 – Estudo 5 – Open Source 6 – Xamarin 7 – Node.js 8 – Democracia organizacional 9 – O programador poliglota ... Toda semana em:
  • 13.
  • 14. Acreditamos que a diversidade, em suas diversas expressões, deve ser respeitada e valorizada, e que uma sociedade mais diversa é uma sociedade melhor. diversidade.tech
  • 17.
  • 19. Código gerenciado Generics Language Integrated Query Dinamismo + paridade nas linguagens C# 5 + VB 11 Programação assíncrona C# 1 + VB 7 C# 2 + VB 8 C# 3 + VB 9 C# 4 + VB 10 C# 6 + VB 14 Roslyn
  • 20. Código gerenciado Generics Language Integrated Query Dinamismo + paridade nas linguagens C# 5 + VB 11 Programação assíncrona C# 1 + VB 7 C# 2 + VB 8 C# 3 + VB 9 C# 4 + VB 10 C# 6 + VB 14 Roslyn C# 7 + VB 15 Features!
  • 21. Código gerenciado Generics Language Integrated Query Dinamismo + paridade nas linguagens C# 5 + VB 11 Programação assíncrona C# 1 + VB 7 C# 2 + VB 8 C# 3 + VB 9 C# 4 + VB 10 C# 6 + VB 14 Roslyn C# 7 + VB 15 Features! Features! Features!Features!
  • 22. Código gerenciado Generics Language Integrated Query Dinamismo + paridade nas linguagens C# 5 + VB 11 Programação assíncrona C# 1 + VB 7 C# 2 + VB 8 C# 3 + VB 9 C# 4 + VB 10 C# 6 + VB 14 Roslyn C# 7 + VB 15 Features! Features! Features! Features (parte 2)? C# 8 + VB 16?
  • 25. F# 10,000’s Tens of thousands VB 100,000’s Hundreds of thousands C# 1,000,000’s Millions
  • 26.
  • 30. public static int DiceSum(IEnumerable<object> values) { var sum = 0; foreach (var item in values) { if (item is int val) sum += val; else if (item is IEnumerable<object> subList) sum += DiceSum(subList); } return sum; } https://docs.microsoft.com/dotnet/csharp/pattern-matching http://bit.ly/cspatternmatching
  • 31. https://docs.microsoft.com/dotnet/csharp/pattern-matching public static int DiceSum(IEnumerable<object> values) { var sum = 0; foreach (var item in values) { switch (item) { } } return sum; } http://bit.ly/cspatternmatching
  • 32. case 0: break; case int val: sum += val; break; case PercentileDie die: sum += die.Multiplier * die.Value; break; https://docs.microsoft.com/dotnet/csharp/pattern-matching public static int DiceSum(IEnumerable<object> values) { var sum = 0; foreach (var item in values) { switch (item) { } } return sum; } http://bit.ly/cspatternmatching
  • 33. case 0: break; case int val: sum += val; break; case PercentileDie die: sum += die.Multiplier * die.Value; break; https://docs.microsoft.com/dotnet/csharp/pattern-matching case IEnumerable<object> subList when subList.Any(): sum += DiceSum(subList); break; case IEnumerable<object> subList: break; case null: break; default: throw new InvalidOperationException("unknown"); public static int DiceSum(IEnumerable<object> values) { var sum = 0; foreach (var item in values) { switch (item) { } } return sum; } http://bit.ly/cspatternmatching
  • 34. var numbers1 = (1, 2); var objs = ("1", 2); WriteLine($"{numbers1.Item1}, {numbers1.Item2}"); (int one, int two) numbers2 = (1, 2); WriteLine($"{numbers2.Item1}, {numbers2.Item2}"); WriteLine($"{numbers2.one}, {numbers2.two}"); var numbers3 = (one: 1, two: 2); WriteLine($"{numbers3.one}, {numbers3.two}"); (int uno, int due) numbers4 = (one: 1, two: 2); WriteLine($"{numbers4.uno}, {numbers4.due}"); // WriteLine($"{numbers4.one}, {numbers4.two}"); // error https://docs.microsoft.com/dotnet/csharp/tuples http://bit.ly/cstuplas
  • 35. void M() { var (name, company) = Person.Get(); WriteLine($"{name}, {company}"); } class Person { public string Name { get; set; } public string Company { get; set; } public void Deconstruct(out string name, out string company) { name = Name; company = Company; } public static Person Get() => new Person { Name = "…", Company = "…" }; } https://docs.microsoft.com/dotnet/csharp/tupleshttp://bit.ly/cstuplas
  • 36. var numbers = (one: 1, two: 2); var (uno, due) = numbers; WriteLine($"{uno}, {due}"); https://docs.microsoft.com/dotnet/csharp/tuples http://bit.ly/cstuplas
  • 37. if (int.TryParse("1", out int result)) WriteLine(result); if (int.TryParse("1", out var result2)) WriteLine(result2); https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#out-variables http://bit.ly/csoutvars
  • 38. (int x, int y) GetCoordinates() => (1, 2); var (_, y) = GetCoordinates(); https://docs.microsoft.com/dotnet/csharp/discards http://bit.ly/csdiscards
  • 39. void ObjectDeconstruction() { var (name, _) = Person.Get(); } https://docs.microsoft.com/dotnet/csharp/discards http://bit.ly/csdiscards
  • 40. if (int.TryParse("1", out _)) WriteLine("It is a number!"); https://docs.microsoft.com/dotnet/csharp/discards http://bit.ly/csdiscards
  • 41. object o = 1; if (o is Person p) WriteLine(p.Company); else if (o is null) WriteLine("null"); else if (o is var _) WriteLine("Unknown"); https://docs.microsoft.com/dotnet/csharp/discards http://bit.ly/csdiscards
  • 42. ref int Find(int[,] matrix, Func<int, bool> predicate) { for (int i = 0; i < matrix.GetLength(0); i++) for (int j = 0; j < matrix.GetLength(1); j++) if (predicate(matrix[i, j])) return ref matrix[i, j]; throw new InvalidOperationException("Not found"); } void M() { var matrix = new [,] { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 42, 10 } }; ref var item = ref Find(matrix, val => val == 42); WriteLine(item); item = 24; WriteLine(matrix[1, 3]); } https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#ref-locals-and-returns http://bit.ly/csreflocals
  • 43. public ExpressionBodiedMembers(string name) => Name = name; ~ExpressionBodiedMembers() => WriteLine("Finalized!"); private string name; public string Name { get => name; set => name = value; } https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#more-expression-bodied-members http://bit.ly/csmaisebm
  • 44. private string a = GetA() ?? throw new Exception(); private static string GetA() => throw new Exception(); https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#throw-expressions http://bit.ly/csexpthrow
  • 45. int sixteen = 0b0001_0000; int thirtyTwo = 0b0010_0000; int sixtyFour = 0b0100_0000; int oneHundredTwentyEight = 0b1000_0000; long oneHundredBillions = 100_000_000_000; double AvogadroConstant = 6.022_140_857_747_474e23; decimal GoldenRatio = 1.618_033_988_749M; https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#numeric-literal-syntax-improvements http://bit.ly/csnumlit
  • 46. double Average(IEnumerable<int> ns) { double Divide(double a, double b) { if (b == 0) throw new DivideByZeroException(); return a / b; } var sum = ns.Sum(); return Divide(sum, ns.Count()); } https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#local-functions http://bit.ly/cslocalfunc
  • 47. void Add1AndSumAll(int[] ms) { IEnumerable<int> Sum1(IEnumerable<int> ns) { foreach (var n in ns) yield return n + 1; } if (ms == null) throw new NullReferenceException(); WriteLine(Sum1(ms).Sum()); } https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#local-functions http://bit.ly/cslocalfunc
  • 48. public async ValueTask<int> Get5() { await Task.Delay(100); return 5; } https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#generalized-async-return-types http://bit.ly/csasyncgeneral
  • 49. public async ValueTask<int> SumAsync(IEnumerable<ValueTask<int>> ns) { var sum = 0; foreach (var nTask in ns) { var n = await nTask; sum += n; } return sum; } https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#generalized-async-return-types http://bit.ly/csasyncgeneral
  • 51. var x = (f1: 1, f2: 2); var tuple = (x.f1, x.f2, x); https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7-1#inferred-tuple-element-names http://bit.ly/cstuplainfer
  • 52. Func<string, bool> predicate = default; int i = default; N(default); https://docs.microsoft.com/dotnet/csharp/programming-guide/statements-expressions-operators/default-value-expressions http://bit.ly/csliteraldefault
  • 53. (int, int) N(int[] ns = default) => default; string O() { return default; } T P<T>() { T t = default; return t; } https://docs.microsoft.com/dotnet/csharp/programming-guide/statements-expressions-operators/default-value-expressions http://bit.ly/csliteraldefault
  • 54. static async Task<int> Main(string[] args) { await Task.Delay(500); WriteLine("Done"); return 0; } https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7-1#async-main http://bit.ly/csasyncmain
  • 56. void M(int i, int j) { } void N() { M(i: 2, 3); } https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/non-trailing-named-arguments.md http://bit.ly/csntna
  • 57. var m = 0b_101; //5 var n = 0x_00C0; // 192 https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/leading-separator.md http://bit.ly/cs_num
  • 58. class Base { private protected int f; } class DerivedInSameAssembly : Base { void M() { var x = base.f; } } class DerivedInOtherAssembly : Base { void M() { var x = base.f; //error } } https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/private-protected.md http://bit.ly/csprpr
  • 59. Vector Add(in Vector v1, in Vector v2) { v1 = default(Vector); // not OK!! v1.X = 0; // not OK!! Foo(ref v1.X); // not OK!! // OK: return new Vector(v1.X +v2.X, v1.Y + v2.Y); } https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types http://bit.ly/csmodin
  • 60. https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/readonly-ref.md#refin-extension-methods public static Ponto Soma(in this Ponto p1, in Ponto p2) => new Ponto(p1.X + p2.X, p1.Y + p2.Y); void In() { Ponto p1 = new Ponto(1, 2), p2 = new Ponto(3, 4); var pResultado = p1.Soma(p2); var pResultado2 = p1.Soma(new Ponto(3, 4)); var pResultado3 = new Ponto().Soma(new Ponto(3, 4)); } http://bit.ly/csmodin
  • 61. public static Ponto Subtrai(ref this Ponto p1, ref Ponto p2) => new Ponto(p1.X - p2.X, p1.Y - p2.Y); void Ref() { Ponto p1 = new Ponto(1, 2), p2 = new Ponto(3, 4); var pResultado = p1.Subtrai(ref p2); p1.Subtrai(ref new Ponto()); // não compila new Ponto().Subtrai(ref p1); // não compila } https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/readonly-ref.md#refin-extension-methods http://bit.ly/csextref
  • 63. ref readonly Vector FetchOrigin() => ref origin; void M() { var v1 = new Vector(1, 2, 3); var v2 = new Vector(4, 5, 6); var vSum = Add(v1, v2); ref readonly var origin = ref FetchOrigin(); } private readonly Vector origin = new Vector(0, 0, 0); https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types http://bit.ly/csretrefro
  • 64. ref readonly var origin = ref FetchOrigin(); var origin2 = FetchOrigin(); // copy created https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types http://bit.ly/csretrefro
  • 65. readonly struct Ponto { public Ponto(float x, float y) { X = x; Y = y; } public float X { get; } public float Y { get; } private readonly static Ponto origem = new Ponto(); public static ref readonly Ponto Origem => ref origem; } https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types#readonly-struct-type http://bit.ly/csrostruct
  • 66. ref readonly var p = ref Ponto.Origem; var x = p.X; // sem cópia https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types#readonly-struct-type http://bit.ly/csrostruct
  • 67. ref int M() { var arr = new[] { 1, 2, 3 }; var otherArr = new[] { 4, 5, 6 }; ref var r = ref (arr != null ? ref arr[0]: ref otherArr[0]); Foo(ref (arr != null ? ref arr[0]: ref otherArr[0])); (arr != null ? ref arr[0]: ref otherArr[0]) = 1; return ref (arr != null ? ref arr[0]: ref otherArr[0]); } void Foo(ref int i) => i = 42; https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/conditional-ref.md http://bit.ly/csternarioref
  • 68. ref struct TwoSpans<T> { // pode ter campos desde que não sejam classes public Span<T> first; public Span<T> second; } // erro: arrays of ref-like types are not allowed. TwoSpans<int>[] arr = null; https://docs.microsoft.com/en-us/dotnet/csharp/reference-semantics-with-value-types#ref-struct-type
  • 69. readonly ref struct ReadOnlyRefPoint2D { public int X { get; } public int Y { get; } public ReadOnlyRefPoint2D(int x, int y) => (X, Y) = (x, y); } https://docs.microsoft.com/dotnet/csharp/reference-semantics-with-value-types#readonly-ref-struct-type
  • 71. public class Cartesian { public int X { get; } public int Y { get; } } public class Polar { public static bool operator is(Cartesian c, out double R, out double Theta) { R = Math.Sqrt(c.X * c.X + c.Y * c.Y); Theta = Math.Atan2(c.Y, c.X); return c.X != 0 || c.Y != 0; } } void M() { var c = new Cartesian(3, 4); if (c is Polar(var R, _)) WriteLine(R); } https://github.com/dotnet/csharplang/blob/master/proposals/patterns.md
  • 72. https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md public class Bar : Foo { private readonly int field1 = int.TryParse(SomeStatic.Text, out int value) ? value : -1; public int Value { get; } public Bar(string text) : base(int.TryParse(text, out int value)) => Value = value; }
  • 76. void N(string? aNullableString, bool condition) { WriteLine(aNullableString.Length); // warning if (aNullableString != null) WriteLine(aNullableString); // no warning if (!string.IsNullOrWhiteSpace(aNullableString)) WriteLine(aNullableString!.Length); // I know better var anotherNullableString = condition ? "Hello" : aNullableString; WriteLine(anotherNullableString.Length); // warning var yetAnotherNullableString = condition ? "Hello" : null; WriteLine(yetAnotherNullableString.Length); // warning string nonNullableString = null; //warning WriteLine(nonNullableString); // no warning } https://github.com/dotnet/csharplang/blob/master/proposals/nullable-reference-types.md https://github.com/dotnet/roslyn/blob/features/NullableReferenceTypes/docs/features/NullableReferenceTypes/README.md
  • 77. async Task M() { foreach await (var i in GetStream()) WriteLine(i); } IAsyncEnumerable<int> GetStream() => new[] { 1, 2, 3 }.ToAsyncEnumerable(); async IAsyncEnumerable<int> MyIterator() { for (int i = 0; i < 100; i++) { await Task.Delay(1000); yield return i; } } https://github.com/dotnet/csharplang/blob/master/proposals/async-streams.md
  • 78. using await (IAsyncDisposable resource = await store.GetRecordAsync(…)) { … } class Foo : IAsyncDisposable { public async Task DisposeAsync() { await ... } } https://github.com/dotnet/csharplang/blob/master/proposals/async-streams.md
  • 79. interface I { void M() { WriteLine("I.M"); } } class C : I { } // OK void M() { I i = new C(); i.M(); // prints "I.M" } https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md
  • 80. class Person : IEquatable<Person> { public string First { get; } public string Last { get; } public Person(string First, string Last) => (this.First, this.Last) = (First, Last); public void Deconstruct(out string First, out string Last) => (First, Last) = (this.First, this.Last); public bool Equals(Person other) => other != null && First == other.First && Last == other.Last; public override bool Equals(object obj) => obj is Person other ? Equals(other) : false; public override int GetHashCode() => GreatHashFunction(First, Last); … } class Person(string First, string Last); https://github.com/dotnet/csharplang/blob/master/proposals/records.md
  • 81. extension class Enrollee extends Person { // static field static Dictionary<Person, Professor> enrollees = new Dictionary<Person, Professor>(); // instance method public void Enroll(Professor supervisor) { enrollees[this] = supervisor; } // instance property public Professor Supervisor => enrollees.TryGetValue(this, out var supervisor) ? supervisor : null; // static property public static ICollection<Person> Students => enrollees.Keys; // instance constructor public Person(string name, Professor supervisor) : this(name) { this.Enroll(supervisor); } } https://github.com/dotnet/csharplang/issues/192
  • 82.
  • 83. #mvpconf Encerramento: • Considerações Finais • Perguntas e Respostas • Agradecimentos
  • 84. w w w. l a m b d a 3 . c o m . b r Obrigado! Giovanni Bassi