C# 8.0 is available in .Net Core 3.0 & .Net Standard.
Using Declarations
Now we can use using as a declaration rather than as a block.
using var file = new System.IO.StreamWriter(“WriteLines2.txt”);
Here the variable file will be disposed after end of scope.
Static Local Functions
Static Local Functions can be created within a Method which will not consume any Instance variables.
int M()
{
int y = 5; int x = 7;
return Add(x, y);
static int Add(int left, int right) => left + right;
}
Default Interface Methods
We can add default methods in Interfaces. This will help in later versions of Interfaces.
interface IDefaultInterface
{
int GetAge()
{
return 18;
}
}
New Switch Structure
public static RGBColor FromRainbow(Rainbow colorBand)
=> colorBand switch {
Rainbow.Red => new RGBColor(0xFF, 0x00, 0x00),
Rainbow.Orange => new RGBColor(0xFF, 0x7F, 0x00),
_ => throw new ArgumentException(message: “invalid enum value”, paramName: nameof(colorBand)), };
// Saves “case” statement
More
https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8