C# Interactive


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:

  1. Use some third-party tools (like LINQPad);
  2. Open additional instance of Visual Studio with “ConsoleApplication1” project;
  3. Use online compilers;
  4. 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).InteractiveWindowAfter that you are ready to go.

For me there are two important sub-features of IntelliSense, which are available directly in C# Interactive window:

  1. Namespace suggestion;
  2. 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:

AddUsing

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!

MemberList

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s