SlideShare a Scribd company logo
Novedades de C# 8
• Germán Küber
• Software Architect & Developer
NET-Baires
http://germankuber.com.ar
@germankuber
germankuber
Readonly members
public struct Point
{
public double X { get; set; }
public double Y { get; set; }
public double Distance => Math.Sqrt(X * X + Y * Y);
public override string ToString() =>
$"({X}, {Y}) is {Distance} from the origin";
}
public struct Point
{
public double X { get; set; }
public double Y { get; set; }
public double Distance => Math.Sqrt(X * X + Y * Y);
public readonly override string ToString() =>
$"({X}, {Y}) is {Distance} from the origin";
}
public struct Point
{
public double X { get; set; }
public double Y { get; set; }
public readonly double Distance => Math.Sqrt(X * X +
Y * Y);
public readonly override string ToString() =>
$"({X}, {Y}) is {Distance} from the origin";
}
public readonly void Translate(int xOffset,
int yOffset)
{
X += xOffset;
Y += yOffset;
}
Default interface methods
public interface ICustomer
{
IEnumerable<IOrder> PreviousOrders { get; }
DateTime DateJoined { get; }
}
public interface ICustomer
{
IEnumerable<IOrder> PreviousOrders { get; }
DateTime DateJoined { get; }
public decimal ComputeLoyaltyDiscount()
{
DateTime TwoYearsAgo = DateTime.Now.AddYears(-2);
if ((DateJoined < TwoYearsAgo)
&& (PreviousOrders.Count() > 10))
{
return 0.10m;
}
return 0;
}
}
var customer = new Customer();
customer.ComputeLoyaltyDiscount();
ICustomer customer2 = new Customer();
customer2.ComputeLoyaltyDiscount();
public class Customer : ICustomer
{
public IEnumerable<IOrder> PreviousOrders { get; set; }
public DateTime DateJoined { get; set; }
}
public class Customer : ICustomer
{
public IEnumerable<IOrder> PreviousOrders { get; set; }
public DateTime DateJoined { get; set; }
public decimal ComputeLoyaltyDiscount()
{
return default;
}
}
public interface ICustomer
{
public static void SetLoyaltyThresholds(int minimumOrders = 10)
{
orderCount = minimumOrders;
}
private static int orderCount = 10;
private static decimal discountPercent = 0.10m;
public decimal ComputeLoyaltyDiscount()
{
//...
}
}
ICustomer customer2 = new Customer();
ICustomer.SetLoyaltyThresholds(12);
customer2.ComputeLoyaltyDiscount();
Pattern matching
Switch expressions
public enum Rainbow
{
Red,
Orange,
Yellow,
Green,
Blue,
Indigo,
Violet
}
public static RGBColor FromRainbowClassic(Rainbow colorBand)
{
switch (colorBand)
{
case Rainbow.Red:
return new RGBColor(0xFF, 0x00, 0x00);
case Rainbow.Orange:
return new RGBColor(0xFF, 0x7F, 0x00);
case Rainbow.Yellow:
default:
throw new ArgumentException();
};
}
public static RGBColor FromRainbow(Rainbow colorBand) =>
colorBand switch
{
Rainbow.Red => new RGBColor(0xFF, 0x00, 0x00),
Rainbow.Orange => new RGBColor(0xFF, 0x7F, 0x00),
Rainbow.Yellow => new RGBColor(0xFF, 0xFF, 0x00),
Rainbow.Green => new RGBColor(0x00, 0xFF, 0x00),
Rainbow.Blue => new RGBColor(0x00, 0x00, 0xFF),
Rainbow.Indigo => new RGBColor(0x4B, 0x00, 0x82),
Rainbow.Violet => new RGBColor(0x94, 0x00, 0xD3),
_ => throw new ArgumentException(),
};
Property patterns
public static decimal ComputeSalesTax(Address location,
decimal salePrice) =>
location switch
{
{ State: "WA" } => salePrice * 0.06M,
{ State: "MN" } => salePrice * 0.75M,
{ State: "MI" } => salePrice * 0.05M,
_ => 0M
};
Using declarations
int WriteLinesToFile(IEnumerable<string> lines)
{
int skippedLines = 0;
using (var file = new StreamWriter("WriteLines2.txt"))
{
foreach (string line in lines)
{
}
} // file is disposed here
return skippedLines;
}
nt WriteLinesToFile(IEnumerable<string> lines)
{
using var file = new StreamWriter("WriteLines2.txt");
int skippedLines = 0;
foreach (string line in lines)
{
}
return skippedLines;
// file is disposed here
}
Static local functions
int M()
{
int y;
LocalFunction();
return y;
void LocalFunction() => y = 0;
}
int M()
{
int y = 5;
int x = 7;
return Add(x, y);
static int Add(int left, int right) => left + right;
}
Asynchronous streams
Asynchronous streams
• Se declara con el modificador async
• Devuelve IAsyncEnumerable<T>
• Contiene instrucciones yield
• Utilizar await delante del foreach
public static async IAsyncEnumerable<int> GenerateSequence()
{
for (int i = 0; i < 20; i++)
{
await Task.Delay(100);
yield return i;
}
}
await foreach (var number in GenerateSequence())
{
Console.WriteLine(number);
}
Indices and ranges
Asynchronous streams
• System.Index representa un índice en una secuencia.
• índice desde el operador final ^
• System.Range representa un subrango de una secuencia.
• El operador de intervalo ..
var words = new string[]
{
// index from start index from end
"The", // 0 ^9
"quick", // 1 ^8
"brown", // 2 ^7
"fox", // 3 ^6
"jumped", // 4 ^5
"over", // 5 ^4
"the", // 6 ^3
"lazy", // 7 ^2
"dog" // 8 ^1
}; // 9 (or words.Le
Recuperar última palabra
Console.WriteLine($"The last word is {words[^1]}");
Recupera un subrango
string[] quickBrownFox = words[1..4];
Incluye words[^2] y words[^1]
var lazyDog = words[^2..^0];
Null-coalescing assignment
??=
List<int> numbers = null;
int? i = null;
numbers ??= new List<int>();
numbers.Add(i ??= 17);
numbers.Add(i ??= 20);
Console.WriteLine(string.Join(" ", numbers)); // output:
17 17
Console.WriteLine(i); // output: 17
Gracias !!!
• Germán Küber
• Software Architect & Developer
NET-Baires
http://germankuber.com.ar
@germankuber
Recursos
• https://www.germankuber.com.ar/novedades-en-c-8/
• https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-
8
• https://www.youtube.com/watch?v=L2BvrXnaOy0
• https://www.youtube.com/watch?v=VdC0aoa7ung

More Related Content

PDF
Polymorphism
PDF
C++ TUTORIAL 8
PDF
C++ TUTORIAL 3
PDF
Implementing stack
PDF
Container adapters
PDF
C++ TUTORIAL 5
PDF
C++ programs
PDF
C++ TUTORIAL 4
Polymorphism
C++ TUTORIAL 8
C++ TUTORIAL 3
Implementing stack
Container adapters
C++ TUTORIAL 5
C++ programs
C++ TUTORIAL 4

What's hot (20)

PDF
Stl algorithm-Basic types
PDF
C++ TUTORIAL 1
PDF
Static and const members
PDF
C++ Programming - 1st Study
PDF
Inheritance and polymorphism
PDF
C++ Programming - 4th Study
PDF
C++ Programming - 2nd Study
PDF
Understanding storage class using nm
PDF
C++ TUTORIAL 9
PDF
C++ TUTORIAL 10
PDF
C++ TUTORIAL 2
PPTX
New presentation oop
PDF
C++ TUTORIAL 7
PDF
C++ TUTORIAL 6
DOCX
C++ file
PDF
Array notes
PDF
C++ Programming - 3rd Study
PDF
C++ Question on References and Function Overloading
PPT
Cquestions
DOCX
2 a networkflow
Stl algorithm-Basic types
C++ TUTORIAL 1
Static and const members
C++ Programming - 1st Study
Inheritance and polymorphism
C++ Programming - 4th Study
C++ Programming - 2nd Study
Understanding storage class using nm
C++ TUTORIAL 9
C++ TUTORIAL 10
C++ TUTORIAL 2
New presentation oop
C++ TUTORIAL 7
C++ TUTORIAL 6
C++ file
Array notes
C++ Programming - 3rd Study
C++ Question on References and Function Overloading
Cquestions
2 a networkflow
Ad

Similar to C sharp 8 (20)

PPT
Lo Mejor Del Pdc2008 El Futrode C#
PDF
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
PPTX
C++ lectures all chapters in one slide.pptx
DOCX
PPTX
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
PPTX
Laziness, trampolines, monoids and other functional amenities: this is not yo...
PDF
Les nouveautés de C# 6
PPSX
C# 6.0 - April 2014 preview
PDF
PDF
TypeScript Introduction
PDF
Laziness, trampolines, monoids and other functional amenities: this is not yo...
PPTX
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
PPT
DOC
oop Lecture 4
PPTX
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
PPTX
New C# features
PDF
C# 7.x What's new and what's coming with C# 8
PDF
C++ practical
PPTX
How to add an optimization for C# to RyuJIT
PDF
Дмитрий Верескун «Синтаксический сахар C#»
Lo Mejor Del Pdc2008 El Futrode C#
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
C++ lectures all chapters in one slide.pptx
TDC2016POA | Trilha .NET - C# como você nunca viu: conceitos avançados de pro...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Les nouveautés de C# 6
C# 6.0 - April 2014 preview
TypeScript Introduction
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
oop Lecture 4
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
New C# features
C# 7.x What's new and what's coming with C# 8
C++ practical
How to add an optimization for C# to RyuJIT
Дмитрий Верескун «Синтаксический сахар C#»
Ad

More from Germán Küber (20)

PPTX
Explorando el Diseño de la Memoria en Rust
PPTX
De Código a Ejecución: El Papel Fundamental del MSIL en .NET
PPTX
Mev Rapido.pptx
PPTX
Que son los smart contracts.pptx
PPTX
De 0 a blockchain developer en 3 meses
PPTX
Patrones funcionales
PPTX
Patrones de diseño en solidity
PPTX
Vertical slice architecture
PPTX
De 0 a blockchain developer en 3 meses
PPTX
Diamon pattern presentation
PPTX
Patrones funcionales
PPTX
Defensive code
PPTX
Programación Funcional C#
PPTX
Unit testing consejos
PPTX
Defensive code C#
PPTX
Event sourcing
PPTX
Arquitectura en aplicaciones Angular y buenas practicas.
PPTX
Un mundo sin if. generics al rescate
PPTX
Azure 360º para Desarrolaldores
PPTX
Vertical slice architecture
Explorando el Diseño de la Memoria en Rust
De Código a Ejecución: El Papel Fundamental del MSIL en .NET
Mev Rapido.pptx
Que son los smart contracts.pptx
De 0 a blockchain developer en 3 meses
Patrones funcionales
Patrones de diseño en solidity
Vertical slice architecture
De 0 a blockchain developer en 3 meses
Diamon pattern presentation
Patrones funcionales
Defensive code
Programación Funcional C#
Unit testing consejos
Defensive code C#
Event sourcing
Arquitectura en aplicaciones Angular y buenas practicas.
Un mundo sin if. generics al rescate
Azure 360º para Desarrolaldores
Vertical slice architecture

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Big Data Technologies - Introduction.pptx
PDF
cuic standard and advanced reporting.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
Teaching material agriculture food technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Digital-Transformation-Roadmap-for-Companies.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation
Big Data Technologies - Introduction.pptx
cuic standard and advanced reporting.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
Spectroscopy.pptx food analysis technology
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Teaching material agriculture food technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx

C sharp 8

Editor's Notes

  • #18:  Hay menos palabras clave case y break repetitivas y menos llaves.
  • #20:  Hay menos palabras clave case y break repetitivas y menos llaves.