C# REPL – With the Visual Studio 2015 Update 1, a C# REPL was snuck in tucked away under View, Other Windows, C# Interactive. So what is a REPL? Well it is a language shell (C# Interactive shell or C# shell) that allows a developer to input expressions which it will evaluate and return a result. Mads Torgersen also mentioned the C# REPL in a talk he did at DDD Brisbane 2015.
What can you do with the C# Interactive window? Have a look at the following code.
In the C# Interactive window, I imported the static System.Math (new in C# 6) which allows me to use the Math class without typing Math [dot] before each method. As you can see, I just typed in Round(88.61) instead of Math.Round(88.61) and hit the return key. The REPL then returned the result in the C# Interactive window. You will also see that it includes intelisense.
You can use pretty much any expression in the C# REPL. The next example I’m importing System.Console which will allow me to just use WriteLine. I then use string interpolation to output the result of Sqrt(64).
The C# REPL Visual Studio 2015 enhancement is a very neat feature and something I’m going to be using a lot indeed. Many times while writing code you might want to quickly run a small piece of code (Substring anyone?) to see what the result will be. The C# Interactive window now allows you to do just that. To get an idea of all you can do with the C# Interactive window, type #help and hit return. This will list a whole list of keyboard shortcuts, REPL commands and Script directives.
Have fun and happy programming. Oh and by the way, thanks Mads and the C# team!