Use C# interactive in Visual Studio to experiment with your code on the fly

I needed to quickly test a regular expression, and the new feature of Visual Studio 2015 came to the rescue: C# Interactive

Published:

You will find this under View → Other Windows → C# Interactive

In my case I wanted to test how the Regex.IsMatch() method handled strings that were null or empty. Note that I had to import .NET's RegularExpressions library.

> string href = null;
> using System.Text.RegularExpressions;
> Regex.IsMatch(href, @"^http://")
System.ArgumentNullException: Value cannot be null
> href = "";
> Regex.IsMatch(href, @"^http://")
false
> href = "http://www.test.com";
> Regex.IsMatch(href, @"^http://")
true

Categories: .NET C#

Comments