SlideShare una empresa de Scribd logo
1 de 91
Descargar para leer sin conexión
w w w. l a m b d a 3 . c o m . b r
Novidades do C# 7 e 8
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
bit.ly/novidadescsharp7
Agenda
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");
}
https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#ref-locals-and-returns
http://bit.ly/csreflocals
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
void M()
{
Span<int> arr = stackalloc int[3];
}
https://msdn.microsoft.com/en-us/magazine/mt814808.aspx
Não é unsafe
C# 7.3
Span<int> RowFive = new Span<int>(PascalsTriangle, 10, 5);
fixed (int* ptrToRow = RowFive)
{
// Soma os números 1,4,6,4,1
var sum = 0;
for (int i = 0; i < RowFive.Length; i++)
{
sum += *(ptrToRow + i);
}
Console.WriteLine(sum);
}
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/pattern-based-fixed.md
int[] PascalsTriangle = {
1,
1, 1,
1, 2, 1,
1, 3, 3, 1,
1, 4, 6, 4, 1,
1, 5, 10, 10, 5, 1 };
Span<T>.GetPinnableReference()
unsafe struct S
{
public fixed int myFixedField[10];
}
class C
{
private static S s = new S();
unsafe public void M()
{
int p = s.myFixedField[5];
}
}
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#indexing-fixed-fields-does-not-require-pinning
// CSharp 7.2
fixed (int* ptr = s.myFixedField)
{
int p = ptr[5];
}
var structs = new StructGrande[]
{ new StructGrande(), new StructGrande() };
ref StructGrande refLocal = ref structs[0];
refLocal = ref structs[1];
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#ref-local-variables-may-be-reassigned
unsafe void M()
{
int* pArr = stackalloc int[3] { 1, 2, 3 };
int* pArr2 = stackalloc int[] { 1, 2, 3 };
Span<int> arr = stackalloc[] { 1, 2, 3 };
}
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#stackalloc-arrays-support-initializers
unsafe public static byte[] ToByteArray<T>
(this T argument) where T : unmanaged
{
var size = sizeof(T);
var result = new byte[size];
byte* p = (byte*)&argument;
for (var i = 0; i < size; i++)
result[i] = *p++;
return result;
}
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#unmanaged-constraint
public static TDelegate TypeSafeCombine<TDelegate>
(this TDelegate source, TDelegate target)
where TDelegate : System.Delegate =>
System.Delegate.Combine(source, target)
as TDelegate;
Action first = () => Console.WriteLine("this");
Action second = () => Console.WriteLine("that");
var combined = first.TypeSafeCombine(second);
combined();
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#delegate-constraints
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;
}
enum Rainbow { Red, Orange, Yellow, Green, Blue, Indigo, Violet }
var map = EnumNamedValues<Rainbow>();
foreach (var pair in map)
Console.WriteLine($"{pair.Key}:t{pair.Value}");
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#enum-constraints
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
var t1 = (1, 2);
var t2 = (3, 4);
var iguais = t1 == t2;
var diferentes = t1 != t2;
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
var query = from text in strings
select int.TryParse(text, out int value)
? value : (int?)null;
public class Foo
{
protected Foo(out int i) => i = 1;
}
public class Bar : Foo
{
public int Value { get; }
public Bar() : base(out int value) => Value = value;
}
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
public class Baz
{
private readonly int field1 =
int.TryParse(SomeStatic.Text, out int value)
? Value
: -1;
}
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
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
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
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
Dictionary<string, List<int>> field =
new() { { "item1", new() { 1, 2, 3 } } };
XmlReader.Create(reader,
new() { IgnoreWhitespace = true });
https://github.com/dotnet/csharplang/blob/master/proposals/target-typed-new.md
// list[Index.CreateFromEnd(1)]
var ultimoItem = list[^1];
// list[Index.CreateFromEnd(2)]
var penultimoItem = list[^2];
// list[3, Index.CreateFromEnd(2)]
var multiDimensional = list[3, ^2];
https://github.com/dotnet/csharplang/blob/master/proposals/ranges.md
// list[Range.Create(2, Index.CreateFromEnd(3))]
var slice1 = list[2..^3];
// list[Range.ToEnd(Index.CreateFromEnd(3))]
var slice2 = list[..^3];
// list[Range.FromStart(2)]
var slice3 = list[2..];
// list[Range.All]
var slice4 = list[..];
// list[Range.Create(1, 2), Range.All]
var multiDimensional = list[1..2, ..]
https://github.com/dotnet/csharplang/blob/master/proposals/ranges.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
public shape SGroup<T>
{
static T operator +(T t1, T t2);
static T Zero { get; }
}
https://github.com/dotnet/csharplang/issues/164
public static AddAll<T>(T[] ts) where T : SGroup<T>
{
var result = T.Zero;
foreach (var t in ts) { result += t; }
return result;
}
https://github.com/dotnet/csharplang/issues/164
public shape SGroup<T>
{
static T operator +(T t1, T t2);
static T Zero { get; }
}
https://github.com/dotnet/csharplang/issues/164
w w w. l a m b d a 3 . c o m . b r
Obrigado!
Giovanni Bassi
@giovannibassi
/giggio.tech

Más contenido relacionado

La actualidad más candente

Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
programming in C++ report
programming in C++ reportprogramming in C++ report
programming in C++ reportvikram mahendra
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual finalAhalyaR
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™Boom Baphomet
 
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)HamHam' Kc
 
Why you should be using structured logs
Why you should be using structured logsWhy you should be using structured logs
Why you should be using structured logsStefan Krawczyk
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloadingmohamed sikander
 
Pattern printing-in-c(Jaydip Kikani)
Pattern printing-in-c(Jaydip Kikani)Pattern printing-in-c(Jaydip Kikani)
Pattern printing-in-c(Jaydip Kikani)Jaydip JK
 
C basics
C basicsC basics
C basicsMSc CST
 
systems programming lab programs in c
systems programming lab programs in csystems programming lab programs in c
systems programming lab programs in cMeghna Roy
 

La actualidad más candente (18)

Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
programming in C++ report
programming in C++ reportprogramming in C++ report
programming in C++ report
 
Function basics
Function basicsFunction basics
Function basics
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
C++ assignment
C++ assignmentC++ assignment
C++ assignment
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Implementing string
Implementing stringImplementing string
Implementing string
 
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
 
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
 
Why you should be using structured logs
Why you should be using structured logsWhy you should be using structured logs
Why you should be using structured logs
 
C++ file
C++ fileC++ file
C++ file
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
 
Pattern printing-in-c(Jaydip Kikani)
Pattern printing-in-c(Jaydip Kikani)Pattern printing-in-c(Jaydip Kikani)
Pattern printing-in-c(Jaydip Kikani)
 
C basics
C basicsC basics
C basics
 
systems programming lab programs in c
systems programming lab programs in csystems programming lab programs in c
systems programming lab programs in c
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 

Similar a TDC2018SP | Trilha .Net - Novidades do C# 7 e 8

C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8Giovanni Bassi
 
.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#Bertrand Le Roy
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 
Transitioning from SQL to MongoDB
Transitioning from SQL to MongoDBTransitioning from SQL to MongoDB
Transitioning from SQL to MongoDBMongoDB
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...Phil Calçado
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»SpbDotNet Community
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project AnalyzedPVS-Studio
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008Luis Enrique
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen TatarynovFwdays
 
The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++Alexander Granin
 
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
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개Reagan Hwang
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Igalia
 

Similar a TDC2018SP | Trilha .Net - Novidades do C# 7 e 8 (20)

C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8C#7, 7.1, 7.2, 7.3 e C# 8
C#7, 7.1, 7.2, 7.3 e C# 8
 
.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
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Transitioning from SQL to MongoDB
Transitioning from SQL to MongoDBTransitioning from SQL to MongoDB
Transitioning from SQL to MongoDB
 
mobl
moblmobl
mobl
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
 
Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»Дмитрий Верескун «Синтаксический сахар C#»
Дмитрий Верескун «Синтаксический сахар C#»
 
The First C# Project Analyzed
The First C# Project AnalyzedThe First C# Project Analyzed
The First C# Project Analyzed
 
Visual studio 2008
Visual studio 2008Visual studio 2008
Visual studio 2008
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
 
The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++The Present and The Future of Functional Programming in C++
The Present and The Future of Functional Programming in C++
 
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
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
ELAVARASAN.pdf
ELAVARASAN.pdfELAVARASAN.pdf
ELAVARASAN.pdf
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
 

Más de tdc-globalcode

TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidadeTDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidadetdc-globalcode
 
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...tdc-globalcode
 
TDC2019 Intel Software Day - ACATE - Cases de Sucesso
TDC2019 Intel Software Day - ACATE - Cases de SucessoTDC2019 Intel Software Day - ACATE - Cases de Sucesso
TDC2019 Intel Software Day - ACATE - Cases de Sucessotdc-globalcode
 
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPATDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPAtdc-globalcode
 
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVinoTDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVinotdc-globalcode
 
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...tdc-globalcode
 
TDC2019 Intel Software Day - Inferencia de IA em edge devices
TDC2019 Intel Software Day - Inferencia de IA em edge devicesTDC2019 Intel Software Day - Inferencia de IA em edge devices
TDC2019 Intel Software Day - Inferencia de IA em edge devicestdc-globalcode
 
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca PublicaTrilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publicatdc-globalcode
 
Trilha .Net - Programacao funcional usando f#
Trilha .Net - Programacao funcional usando f#Trilha .Net - Programacao funcional usando f#
Trilha .Net - Programacao funcional usando f#tdc-globalcode
 
TDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case EasylocusTDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case Easylocustdc-globalcode
 
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?tdc-globalcode
 
TDC2018SP | Trilha Go - Clean architecture em Golang
TDC2018SP | Trilha Go - Clean architecture em GolangTDC2018SP | Trilha Go - Clean architecture em Golang
TDC2018SP | Trilha Go - Clean architecture em Golangtdc-globalcode
 
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QATDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QAtdc-globalcode
 
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendenciaTDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendenciatdc-globalcode
 
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR ServiceTDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Servicetdc-globalcode
 
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NETTDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NETtdc-globalcode
 
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...tdc-globalcode
 
TDC2018SP | Trilha .Net - .NET funcional com F#
TDC2018SP | Trilha .Net - .NET funcional com F#TDC2018SP | Trilha .Net - .NET funcional com F#
TDC2018SP | Trilha .Net - .NET funcional com F#tdc-globalcode
 
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor em .Net Core
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor  em .Net CoreTDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor  em .Net Core
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor em .Net Coretdc-globalcode
 
TDC2018SP | Trilha .Net - Novidades do ASP.NET Core 2.1
TDC2018SP | Trilha .Net - Novidades do ASP.NET Core 2.1TDC2018SP | Trilha .Net - Novidades do ASP.NET Core 2.1
TDC2018SP | Trilha .Net - Novidades do ASP.NET Core 2.1tdc-globalcode
 

Más de tdc-globalcode (20)

TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidadeTDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
 
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
 
TDC2019 Intel Software Day - ACATE - Cases de Sucesso
TDC2019 Intel Software Day - ACATE - Cases de SucessoTDC2019 Intel Software Day - ACATE - Cases de Sucesso
TDC2019 Intel Software Day - ACATE - Cases de Sucesso
 
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPATDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
 
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVinoTDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
 
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
 
TDC2019 Intel Software Day - Inferencia de IA em edge devices
TDC2019 Intel Software Day - Inferencia de IA em edge devicesTDC2019 Intel Software Day - Inferencia de IA em edge devices
TDC2019 Intel Software Day - Inferencia de IA em edge devices
 
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca PublicaTrilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
 
Trilha .Net - Programacao funcional usando f#
Trilha .Net - Programacao funcional usando f#Trilha .Net - Programacao funcional usando f#
Trilha .Net - Programacao funcional usando f#
 
TDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case EasylocusTDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case Easylocus
 
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
 
TDC2018SP | Trilha Go - Clean architecture em Golang
TDC2018SP | Trilha Go - Clean architecture em GolangTDC2018SP | Trilha Go - Clean architecture em Golang
TDC2018SP | Trilha Go - Clean architecture em Golang
 
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QATDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
 
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendenciaTDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
 
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR ServiceTDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
 
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NETTDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
 
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
 
TDC2018SP | Trilha .Net - .NET funcional com F#
TDC2018SP | Trilha .Net - .NET funcional com F#TDC2018SP | Trilha .Net - .NET funcional com F#
TDC2018SP | Trilha .Net - .NET funcional com F#
 
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor em .Net Core
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor  em .Net CoreTDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor  em .Net Core
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor em .Net Core
 
TDC2018SP | Trilha .Net - Novidades do ASP.NET Core 2.1
TDC2018SP | Trilha .Net - Novidades do ASP.NET Core 2.1TDC2018SP | Trilha .Net - Novidades do ASP.NET Core 2.1
TDC2018SP | Trilha .Net - Novidades do ASP.NET Core 2.1
 

Último

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 

Último (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 

TDC2018SP | Trilha .Net - Novidades do C# 7 e 8

  • 1. w w w. l a m b d a 3 . c o m . b r Novidades do C# 7 e 8
  • 2. 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
  • 3.
  • 4. 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:
  • 5.
  • 6. 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. 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
  • 11. 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!
  • 12. 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!
  • 13. 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?
  • 16. F# 10,000’s Tens of thousands VB 100,000’s Hundreds of thousands C# 1,000,000’s Millions
  • 17.
  • 21. 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
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. 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
  • 26. 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
  • 27. var numbers = (one: 1, two: 2); var (uno, due) = numbers; WriteLine($"{uno}, {due}"); https://docs.microsoft.com/dotnet/csharp/tuples http://bit.ly/cstuplas
  • 28. 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
  • 29. (int x, int y) GetCoordinates() => (1, 2); var (_, y) = GetCoordinates(); https://docs.microsoft.com/dotnet/csharp/discards http://bit.ly/csdiscards
  • 30. void ObjectDeconstruction() { var (name, _) = Person.Get(); } https://docs.microsoft.com/dotnet/csharp/discards http://bit.ly/csdiscards
  • 31. if (int.TryParse("1", out _)) WriteLine("It is a number!"); https://docs.microsoft.com/dotnet/csharp/discards http://bit.ly/csdiscards
  • 32. 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
  • 33. 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"); } https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-7#ref-locals-and-returns http://bit.ly/csreflocals
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. 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
  • 43. 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
  • 44. 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
  • 45. (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
  • 46. 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
  • 48. 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
  • 49. 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
  • 50. 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
  • 51. 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
  • 52. 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
  • 53. 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
  • 55. 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
  • 56. 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
  • 57. 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
  • 58. 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
  • 59. 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
  • 60. 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
  • 61. 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
  • 62. void M() { Span<int> arr = stackalloc int[3]; } https://msdn.microsoft.com/en-us/magazine/mt814808.aspx Não é unsafe
  • 64. Span<int> RowFive = new Span<int>(PascalsTriangle, 10, 5); fixed (int* ptrToRow = RowFive) { // Soma os números 1,4,6,4,1 var sum = 0; for (int i = 0; i < RowFive.Length; i++) { sum += *(ptrToRow + i); } Console.WriteLine(sum); } https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/pattern-based-fixed.md int[] PascalsTriangle = { 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, 1, 5, 10, 10, 5, 1 }; Span<T>.GetPinnableReference()
  • 65. unsafe struct S { public fixed int myFixedField[10]; } class C { private static S s = new S(); unsafe public void M() { int p = s.myFixedField[5]; } } https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#indexing-fixed-fields-does-not-require-pinning // CSharp 7.2 fixed (int* ptr = s.myFixedField) { int p = ptr[5]; }
  • 66. var structs = new StructGrande[] { new StructGrande(), new StructGrande() }; ref StructGrande refLocal = ref structs[0]; refLocal = ref structs[1]; https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#ref-local-variables-may-be-reassigned
  • 67. unsafe void M() { int* pArr = stackalloc int[3] { 1, 2, 3 }; int* pArr2 = stackalloc int[] { 1, 2, 3 }; Span<int> arr = stackalloc[] { 1, 2, 3 }; } https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7-3#stackalloc-arrays-support-initializers
  • 68. unsafe public static byte[] ToByteArray<T> (this T argument) where T : unmanaged { var size = sizeof(T); var result = new byte[size]; byte* p = (byte*)&argument; for (var i = 0; i < size; i++) result[i] = *p++; return result; } https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#unmanaged-constraint
  • 69. public static TDelegate TypeSafeCombine<TDelegate> (this TDelegate source, TDelegate target) where TDelegate : System.Delegate => System.Delegate.Combine(source, target) as TDelegate; Action first = () => Console.WriteLine("this"); Action second = () => Console.WriteLine("that"); var combined = first.TypeSafeCombine(second); combined(); https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#delegate-constraints
  • 70. 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; } enum Rainbow { Red, Orange, Yellow, Green, Blue, Indigo, Violet } var map = EnumNamedValues<Rainbow>(); foreach (var pair in map) Console.WriteLine($"{pair.Key}:t{pair.Value}"); https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters#enum-constraints
  • 72. https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md var query = from text in strings select int.TryParse(text, out int value) ? value : (int?)null;
  • 73. public class Foo { protected Foo(out int i) => i = 1; } public class Bar : Foo { public int Value { get; } public Bar() : base(out int value) => Value = value; } https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
  • 74. public class Baz { private readonly int field1 = int.TryParse(SomeStatic.Text, out int value) ? Value : -1; } https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.3/expression-variables-in-initializers.md
  • 77. 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
  • 78. 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
  • 79. 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
  • 80. 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
  • 81. 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
  • 82. Dictionary<string, List<int>> field = new() { { "item1", new() { 1, 2, 3 } } }; XmlReader.Create(reader, new() { IgnoreWhitespace = true }); https://github.com/dotnet/csharplang/blob/master/proposals/target-typed-new.md
  • 83. // list[Index.CreateFromEnd(1)] var ultimoItem = list[^1]; // list[Index.CreateFromEnd(2)] var penultimoItem = list[^2]; // list[3, Index.CreateFromEnd(2)] var multiDimensional = list[3, ^2]; https://github.com/dotnet/csharplang/blob/master/proposals/ranges.md
  • 84. // list[Range.Create(2, Index.CreateFromEnd(3))] var slice1 = list[2..^3]; // list[Range.ToEnd(Index.CreateFromEnd(3))] var slice2 = list[..^3]; // list[Range.FromStart(2)] var slice3 = list[2..]; // list[Range.All] var slice4 = list[..]; // list[Range.Create(1, 2), Range.All] var multiDimensional = list[1..2, ..] https://github.com/dotnet/csharplang/blob/master/proposals/ranges.md
  • 85. 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
  • 86. 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
  • 87. public shape SGroup<T> { static T operator +(T t1, T t2); static T Zero { get; } } https://github.com/dotnet/csharplang/issues/164
  • 88. public static AddAll<T>(T[] ts) where T : SGroup<T> { var result = T.Zero; foreach (var t in ts) { result += t; } return result; } https://github.com/dotnet/csharplang/issues/164
  • 89. public shape SGroup<T> { static T operator +(T t1, T t2); static T Zero { get; } } https://github.com/dotnet/csharplang/issues/164
  • 90.
  • 91. w w w. l a m b d a 3 . c o m . b r Obrigado! Giovanni Bassi @giovannibassi /giggio.tech