Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set C# version for csi.exe

In C# interactive (as part of Visual Studio 2019 or standalone) I'd like to code something like this using C#:

var s = "abcdef";
var s1 = s[2..4];

This gives the following message:

(1,12): error CS0518: Predefined type 'System.Range' is not defined or imported

Is there a way to modify e.g., csi.exe.config or other means in order to support C# 8.0 ?

like image 968
Taisbak Avatar asked Mar 31 '20 08:03

Taisbak


People also ask

How do I run C code in Visual Studio?

After writing the code, right-click on the program, as shown below. Click on the Run Code option or press Ctrl + Alt + N from the button.

What is main () in C?

Every C program has a primary (main) function that must be named main. If your code adheres to the Unicode programming model, you can use the wide-character version of main, wmain. The main function serves as the starting point for program execution.


1 Answers

Update 2020-11-25

It is working in Visual Studio 16.8.2.

Just enter #reset core to switch to .NET Core.


Update 2020-07-14

According to https://github.com/dotnet/roslyn/pull/45046, it will probably work in the next version of Visual Studio 2019.

Adds a new option to #reset command that allows the user to switch Interactive Window host to .NET Core:

  • #reset 32 - switches to .NET Framework 32-bit process
  • #reset 64 - switches to .NET Framework 64-bit process
  • #reset core - switches to .NET Core 64-bit process

Leaves the default to .NET Framework 64-bit for now.


Original answer

It looks like there is no way currently. Because C# Interactive is not able to run Core CLR.

The Interactive Window only supports .NET Framework at this point. Hence features are limited to C# 7.3 and lower. Too enable C# 8 we would need to first enable running on Core CLR (see #4788).

https://github.com/dotnet/roslyn/issues/40341

like image 69
Supa Avatar answered Sep 27 '22 19:09

Supa