.NET Zone
.NET Zone is brought to you in partnership with:
spacer spacer Filip Ekberg
  • Bio
  • Website
  • @fekberg

I am a Software Engineer working with the latest in .NET focusing on Web Development. With a burning heart for programming, I blog and author a book about C#. Filip is a DZone MVB and is not an employee of DZone and has posted 12 posts at DZone. You can read more from them at their website. View Full User Profile

Using the C# Interactive Window that comes with Roslyn: Part 2

spacer Email
Views: 1305
  • Tweet
  • spacer
This article is part of the DZone .NET Zone, which is brought to you in collaboration with the .NET community. Visit the .NET Zone for additional tutorials, videos, opinions, and other resources on this topic.

We Recommend These Resources

Getting Started with Apache Camel - 6/28/2012 - 10:00AM EST

Best Practices for Building High Performance Development Teams

DevOps: From Concepts to Practical Applications Featuring Forrester Research, Inc. and Equinox

VaraLogix Q Product Demo - Application Deployment Automation & Configuration Management in One Solution

5 Critical Application Deployment Mistakes (You Don’t Want to Make)

In the previous post we looked over an introduction to the C# Interactive Window that comes with Roslyn, now let’s have a look at some things in the c# interactive window that will increase your productivity! I want to thank Kevin Pilch-Bisson ( @Pilchie ) for pointing some of these things out.

One question that arise when I showed off the C# Interactive Window at work was: This looks great, but can we use types in our current solution?

Yes, you can and this is one of the things that I think makes this C# Interactive Window very powerful. Here’s how you do it, go on about your day, coding your classes and when you want to fire up the C# Interactive Window you can just right click your solution and select “Reset Interactive from Project” like this:


Now this will bring up the C# Interactive Window like this:


As you might see here you can reference assemblies by writing #r <name> and then import the namespace by writing a using-statement. You can experiment a bit with it, try writing the following:

> #r "System.Windows.Forms"
> System.Windows.Forms.MessageBox.Show("test");

You could also do it like this:

> #r "System.Windows.Forms"
> using System.Windows.Forms;
> MessageBox.Show("test");

Now this is pretty powerful, because now we can do live testing on our objects with intellisense without actually adding or changing anything in our solution. As I said in the previous post this is nice when you want to test code out and play with it. Let’s say that you’re completely new to a project, it lacks good documentation and sure you see all the code files and you can navigate around inside them to learn about them, but how do you test everything out?

You can write tests for yourself, compile, run test and do that over and over again or you can fire up the C# Interactive Window and start playing around.

Have a look at this, I’ve created an instance of my Person class and then I check if the instance is null or not and instantly the result of this expression is printed out (hence REPL). We also get intellisense on our classes which makes exploring and working with the interactive window a blast!


I hope you found this interesting, if you have any thoughts please leave a comment below!

Published at DZone with permission of Filip Ekberg, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

  • roslyn
  • Tutorial
  • C-Sharp
This content was brought to you by DZone for all the information you need on ASP.NET, WPF, XAML, SQL Server, and other pieces of the .NET stack.
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.