I am trying to use the System.Range and System.Index classes with new C# v8.0 construct, see (here). But, I cannot make it work. I have tried under Windows with .NET 5.0 and under Ubuntu with Mono 6 but I got the same result:
First I have changed the .csproj file like that:
<Project Sdk="Godot.NET.Sdk/3.3.0"> <PropertyGroup> <TargetFramework>net472</TargetFramework> <LangVersion>8.0</LangVersion> </PropertyGroup> </Project> Note the <LangVersion> set at 8.0. With that parameter, I can now build the project with this kind of snippet:
int[] nb = {1, 2, 3}; GD.Print(nb[1..2]); But at runtime, I got this error: Predefined type 'System.Range' is not defined or imported
EDIT: To answer the comments.
I had to add using System.Runtime to make the project able to build.
I had tried to change target framework to .net5.0 (that was only possible on Windows). The project was still able to build but the error at runtime was different:
E 0:00:01.563 debug_send_unhandled_exception_error: System.TypeLoadException: Could not resolve type with token 01000010 from typeref (expected class 'System.Range' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') <C++ Error> Unhandled exception <C++ Source> modules/mono/mono_gd/gd_mono_utils.cpp:423 @ debug_send_unhandled_exception_error() But this answer made me think that the Mono assemblies used at runtime needs net472.
Another hint is that an important Godot project that claims to use C# v8.0, the beautiful Thrive, sets net472 and 8.0 in their config file (see here)
usingdirective to access that feature? Or is it really built into the core language? This site claims Godot can use C# 8.0: docs.godotengine.org/en/stable/getting_started/scripting/… \$\endgroup\$