C# Interactive with Visual Studio 2015

April 13, 2016 by Anuraj

C# Visual Studio 2015 Visual Studio CodeProject

Visual Studio 2015 update 1 comes with C# interactive window. C# interactive window is a read-eval-print-loop (REPL) with advanced editor support. It supports features like IntelliSense as well as the ability to redefine functions & classes. After entering a code snippet–which can contain class and function definitions at top-level along with statements–the code executes directly.

You need VS 2015 update 1 or update 2 to use this feature. Once you have one of these versions installed, navigate to View > Other Windows > C# Interactive. This will bring up the Interactive Window.

C# interactive window

Now you can type any valid C# expression or statement and press Enter to evaluate. In the above image, using a C# expression, which will print the result. You can create methods in C# interactive window either typing the whole function or by pasting it.

C# interactive window - Creating functions

If you want to load another assembly to the C# interactive window, you can do this using #r command. Here I am loading a math assembly and I am executing a function inside it.

C# interactive window - External Assembly

You can find more details about C# interactive window here and here

Happy Programming :)

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub