New features in Visual Studio 2015

I’ve been reading the Visual Studio 2015 releasenotes (https://www.visualstudio.com/en-us/news/vs2015-vs.aspx) and while I am waiting for the ASP.Net vNext, here are some things which I find are nice improvements:

Nameof

Nameof provides a refactoring-safe way of getting the name of e.g. a parameter, member or type as a string.
Finally a typesafe way of referencing the name of a variable!

Here’s the old code:stringformat1

 

and here is the new code:

stringinterpolation2

 

No more referencing the wrong variable name when the refactoring missed the “variabele name by string”!

String interpolation

From the docs: “An interpolated string expression looks like a template string that contains expressions. An interpolated string expression creates a string by replacing the contained expressions with the ToString represenations of the expressions’ results.”

Here’s an example:
Code before:

stringinterpolation1

Code with string interpolation

stringinterpolation2

 

And the compiler checks the expressions in the string text!

null-conditional operator

Copied from here (https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6) which contains a good explanation:

Sometimes code tends to drown a bit in null-checking. The null-conditional operator lets you access members and elements only when the receiver is not-null, providing a null result otherwise:

int? length = customers?.Length; // null if customers is null
Customer first = customers?[0]; // null if customers is null

The null-conditional operator is conveniently used together with the null coalescing operator  ?? :

int length = customers?.Length ?? 0; // 0 if customers is null

The null-conditional operator exhibits short-circuiting behavior, where an immediately following chain of member accesses, element accesses and invocations will only be executed if the original receiver was not null:

int? first = customers?[0].Orders.Count();

This example is essentially equivalent to:

int? first = (customers != null) ? customers[0].Orders.Count() : null;

Except that  customers  is only evaluated once.

Lambda Expressions in Debugger Windows

You can now use lambda expressions in the Watch, Immediate, and other debugger windows in C# and Visual Basic.
Lambda expressions are used so frequently that this feature is highly welcomed during debugging sessions!

JSON Editor Improvements

Un-minify context menu. You can right-click the JSON editor and select Un-minify context menu to un-minify any long arrays in the JSON file.

Javascript

Tooling support for AngularJS. Now, when you are writing apps using AngularJS, IntelliSense provides suggestions for Angular controllers, services, factories, directives, and animations.

One thought on “New features in Visual Studio 2015

  1. I love all of the new Visual Studio 2015 features, except the null-conditional operator. I find it hard when reading source code. Probably it needs some time in my mind to automatically read it, without overlooking the ?-mark.

    It’s nice most of the features don’t need a new .NET Framework but are compiler tricks. What do you think about Exception Filters? This is the only C# 6 feature that isn’t purely a compiler trick and needs a new framework.

    Best,

    Mark Monster

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s