TL;DR – Once you try the C# Interactive Window, you will never run another Console App just to try out an API.
You know how they say that if the only tool you have is a hammer, then everything looks like a nail? Well, this is especially true in the software industry. I once witnessed a guy debugging a .NET application with WinDbg just because he is a guru of that tool. At that moment I thought to myself how happy he would be if he only knew the tools available to him with Visual Studio.
Anyway, enough with the jabber, I am here to make you fall in love with the C# interactive window that is available with Visual Studio 2015 update-1.
After finishing the update of you VS, navigate to:
View > Other Windows > C# Interactive
What you should see is a new window that looks like this:
Features, features and features…
Alright, after getting all the boring stuff out of the way, I want to show you what you can do with this. The whole set of features is explained on the official Microsoft GitHub account, so I wont cover everything but give you a taste of the most interesting ways you can use it in your day-to-day development.
- Multi-line support – you can write fully executable script by pressing ‘Shift+Enter’ for a new line, and for actual execution use ‘Ctrl+Enter’ when your script is ready. Consider this snippet:
- Reference external dlls – you can actually load an external dll to play with it’s APIs by using the #r command like this:
This is seriously a powerful tool!
- Use interactive outside VS – you can run this environment even outside Visual Studio by simply executing ‘csi’ in you Developer Command Prompt from VS 2015:
- Loading saved scripts – you can write a common script and load it in to the execution context by using the #load command. This is super cool when you have a script that is loading an entire environment for you that you can work with with specific APIs.
- Execution context – when the window initializes, you can create variables that will live until you type the #reset command. For example try executing the following command, and use the myFile variable in your next commands:
var myFile = new FileInfo(@"c:\users\shonn\desktop\myResume.txt");
- Navigation – You can navigate executed statements history by using ‘Alt+UpArrow’.
Go ahead and explore more features (believe me there are tons!), it is really awesome!
Feel free to leave a comment if this was helpful 🙂