[C#] Update to 9.0

It would be appreciated if C# could be updated to 9.0 from 8.0. This would benefit code golfing exercises as C# 9.0 brings top-level statements. Code can be reduced from this:

using System;
class X
{
    static void Main()
    {
        Console.WriteLine("Hello world!");
    }
}

to this:

using System;
Console.WriteLine("Hello world!");

Currently with C# 8.0 this errors:

The feature ‘top-level statements’ is currently in Preview and unsupported. To use Preview features, use the ‘preview’ language version.csharp(CS8652)

Changes in C# 9.0

2 Likes

we’ve just updated the languages. See
https://www.codingame.com/forum/t/languages-update/1574/223
Also, I’m not sure C# 9.0 is supported on .net core

Part of it is, but to get the full package you need to update from .Net core to .Net 5 too.
I’ve done it recently for my job, that was surprisingly easy :slightly_smiling_face:

1 Like

Yeah, it seems that C# 9.0 is not supported by .NET Core (“C# 9.0 is supported only on .NET 5 and newer versions.”). However, as Djoums said, upgrading from .NET Core to .NET 5 isn’t hard either.

Edit: it might be possible to use C# 9.0 on .NET Core, although I’m not sure if it will trigger a compiler error.

You can but it’s limited, quoting from someone else :

Using <LangVersion>9.0</LangVersion> with .Net Core 3.1 is possible, however there are three categories of features in C# :

  • features that are entirely part of the compiler, those will work.
  • features that require BCL additions. Since .Net Core is on an older BCL, those would need to be backported (for example to use init setters and records, you could import https://github.com/manuelroemer/IsExternalInit).
  • features that require runtime additions, those cannot be added and won’t work (for example default interface implementations in C# 8 and covariant return types in C# 9).

Upgrading to .Net 5 is much simpler overall.

1 Like

I think it’ll be part of the next update. Sorry!

1 Like