« Csharp 8 » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 3 : Ligne 3 :
* [https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8 What's new in C# 8.0]
* [https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8 What's new in C# 8.0]
* [https://docs.microsoft.com/en-gb/dotnet/csharp/language-reference/configure-language-version C# language versioning]
* [https://docs.microsoft.com/en-gb/dotnet/csharp/language-reference/configure-language-version C# language versioning]
= Switch expression =
<kode lang='cs'>
switch (i)
{
    case 1:
        return "One";
    default:
        throw new Exception("Invalid value");
}
i switch
{
    1 => "One",
    _ => throw new Exception("Invalid value")
};
</kode>


= [https://stackoverflow.com/questions/56651472/does-c-sharp-8-support-the-net-framework .NET Framework] =
= [https://stackoverflow.com/questions/56651472/does-c-sharp-8-support-the-net-framework .NET Framework] =

Version du 4 mars 2020 à 15:36

Liens

Switch expression

Cs.svg
switch (i)
{
    case 1:
        return "One";
    default:
        throw new Exception("Invalid value");
}

i switch
{
    1 => "One",
    _ => throw new Exception("Invalid value")
};

.NET Framework

The C# 8 / .NET Framework combination is not officially supported by Microsoft.
It can be forced by editing the csproj file.

MyProject.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <LangVersion>8.0</LangVersion>
  • default interface members won't work
  • ssynchronous streams and indices and ranges will need polyfill nuget package