Dot Net For All

Working with REPL in Visual Studio

Hello friends, Visuals studio 2015 was released with a very useful and beneficial feature called as REPL. Full form of REPL is Read Evaluate Print Loop. In this article I will show you how this can be a useful feature from developer point of view.

What is REPL?

REPL allows the developer to write the interactive code which in turn will be complied on the run.

While the compiler will keep waiting for the nest command from the developer. This is also know as .NET interactive window.

The benefit of REPL is that it allows to work on the newer API’s or test our small piece of code without opening a new Visual studio.

How to Work With REPL in Visual Studio?

You can open the REPL interactive window by going to View > Other Windows > C# Interactive as shown in the figure below.

And you can see in the bottom of the Visual Studio there is a window named C# Interactive.

Start Using REPL

In the above figure I have done number of operation.

In the first operation I am comparing two values using wrong operator. And hence I am getting an error.

Next I am using REPL as calculator. Where I am adding 2 + 2. And getting the result as 4.

Finally in the last operation I am creating a first class function which returns the double of the input values.

I have created a list named range, passed the function to the Select LINQ method. Further I assigned the output to the “doubles” variable.

And printed the result in the last line of code. This is a C# code I have written and I am able to get the output without compiling and running the code snippet.

Conclusion

REPL can be very helpful and productive tool if we want to do a quick check of our small code snippets and methods without writing test cases.

Top career enhancing courses you can't miss

My Learning Resource

Excel your system design interview