Using an interactive shell (REPL)

C#:
Using an interactive shell (REPL)

How to:

Fire up a REPL in your C# environment using the C# Interactive window or run dotnet-script in your terminal. Here’s a taste of using it:

> var greeting = "Hello, REPL!";
> Console.WriteLine(greeting);
Hello, REPL!
> 

You instantly get feedback. No compile and run steps. Just code and see.

Deep Dive

REPL journeyed from Lisp to modern languages, thriving in dynamic ones like Python. With C#, Roslyn brought the REPL closer to developers. csi for Roslyn, and dotnet-script for .NET Core, are solid options. A deeper cut: they evaluate code per line, not all together, a different execution model versus typical C# apps. This impacts state persistence across executions and the scope of variables.

Visual Studio’s C# Interactive window is a REPL powered by Roslyn. It has Intellisense, multiple references, and NuGet package support. Quite a step up from early command line experiments.

For alternative languages, Python uses IDLE, JavaScript has Node.js’s REPL, and F# ships with F# Interactive. Each fosters instant feedback loops, invaluable for testing small code snippets or understanding language features.

See Also