Recently I’ve installed the Update 1 for my Visual Studio 2015 and in my opinion the killer feature of this update is the C# Interactive window.
I’ve asked couple of .NET developers “What you are doing, when you need to quickly check one small code snippet (for example, LINQ expression or Regular Expression behavior for different input strings)?”. Here are the couple of popular answers:
- Use some third-party tools (like LINQPad);
- Open additional instance of Visual Studio with “ConsoleApplication1” project;
- Use online compilers;
- Use Immediate Window.
In my opinion each of these solutions has some advantages and disadvantages. For example: online compiler and immediate window miss the IntelliSense feature.
But now, we have a C# Interactive window, which is a quite powerful tool with the support of IntelliSense!
At first, to show this window you need to go to “View -> Other Windows -> C# Interactive” (please, refer to screenshot below).After that you are ready to go.
For me there are two important sub-features of IntelliSense, which are available directly in C# Interactive window:
- Namespace suggestion;
- List of members;
Let’s take a brief look. For example you need to test some regular expression.
var testRegex = new Regex("x[a]x");
Basically this code will not work. But C# Interactive will help you by showing the suggestion to add namespace using. It will look like on the screenshot below:
After doing this you code will be modified by Visual Studio and will look like this:
using System.Text.RegularExpressions; var testRegex = new Regex("x[a]x");
Note: to add new line of code, without executing it use Shift+Enter, rather then Enter.
Now you want to show the result of the Regular Expression execution in Console. You are typing Console. press Ctrl+Space and receive a list of available members. That’s amazing!
Also, there are two small and nice buttons at the top of the C# Interactive window: “History Previous”, “History Next”. Basically it’s a standard functionality, available in most of the console-like applications. Nice and very useful.
Hopefully you’ll enjoy this functionality as I do.