C# REPL

Talles L - Sep 12 '20 - - Dev Community

Having a quick C# REPL can help a lot on testing little snippets of code.

.NET Fiddle

The quickest one is probably .NET Fiddle, which can be accessed by your web browser and don’t required any setup or registering:

csi.exe

There’s a C# REPL in Visual Studio on View > Other Windows > C# Interactive:

Which opens:

You can also fire csi.exe directly outside of Visual Studio:

Having Visual Studio 2017 Enterprise and Visual Studio 2019 Community installed on my Windows machine, I’ve managed to find it on:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csi.exe

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\csi.exe
Enter fullscreen mode Exit fullscreen mode

dotnet-script

It seems that csi.exe is not available for folks using .NET Core on Linux yet. Fortunately, there’s dotnet-script:

$ dotnet tool install -g dotnet-script
You can invoke the tool using the following command: dotnet-script
Tool 'dotnet-script' (version '0.53.0') was successfully installed.
$ dotnet script
> Math.Pow(3, 2)
9
Enter fullscreen mode Exit fullscreen mode

csharprepl (.NET 7)

If you are already on .NET 7 you can install csharprepl:

dotnet tool install -g csharprepl
Enter fullscreen mode Exit fullscreen mode

Just call csharprepl from your terminal and you'll drop into a fully functional REPL (syntax highlight, auto complete, documentation, etc):

Other alternatives

I haven’t tested it myself, but a quick search gives LINQPad and CS-Script as alternatives.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .