You are here
Home > Programming > C# REPL – Introducing C# Interactive

C# REPL – Introducing C# Interactive

C# REPL

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.

C# REPL

What can you do with the C# Interactive window? Have a look at the following code.

C# REPL

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.

CSharp Interactive 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).

C# REPL

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.

CSharp Interactive Help

Have fun and happy programming. Oh and by the way, thanks Mads and the C# team!

 

Dirk Strauss
Dirk is a Software Developer and Microsoft MVP from South Africa. He loves all things Technology and is slightly addicted to Twitter and Jimi Hendrix. Apart from writing code, he also enjoys writing human readable articles. "I love sharing knowledge and connecting with people from around the world. It's the diversity that makes life so beautiful." Dirk feels very strongly that pizza is simply not complete without Tabasco, that you can never have too much garlic, and that cooking the perfect steak is an art he has yet to master.

Similar Articles

Top