The Interactive Window in Visual Studio is a great utility to play around the code, language features, API’s and other .NET framework features. It is a REPL (Read–eval–print loop) that provides us an environment for live coding and evaluate expression or code snippet based on our inputs. The Interactive Window also support features like IntelliSense, syntax highlighting and navigating through executed commands.
We can also includes references to external dependency and also using namespaces like a normal Visual Studio Editor features.
To launch the Interactive window navigate through Views > Other Windows > C# Interactive.
Here is some of the common examples to start with…
Following example shows how we can define a basic variable, and write a basic C# code with the interactive window.
You will have full intellisense and tool tip support as similar to our main Visual Studio code editor.
You can also use the different language feature like I have used the string interpolation feature here – Easily format strings – String interpolation in C# 6.0
Now, weather it a simple C# code, complex code or even a LINQ you can execute live within the editor.
And of course you can do declare methods and use it. You might think what could the use of it ? Think in a way, you can write your method here, execute and test and finally when it is working fine with expected output you can move it to your main code.
The Interactive Window also support the using namespace, and once included then you can leverage all the feature for those assembly.
This tool also support error handling both compile and runtime as shown in below screenshot
well, to summarize, the Interactive window is for quick prototyping, checking some quick output of C# code without creating some new projects. This is really great utility available with Visual Studio and can help us to do quick code experiment. !
Hope this helps !