3 Features Coming in Microsoft C# 6.0 to Make Developers Even More Efficient

Microsoft has announced a new version of Visual Studio 2015 that will include the next version of C# 6.0. Professional software developers around the world will be evaluating what’s coming and deciding how to integrate programming language syntax into their coding style.

Below are my 3 favorite features slated for the next version of C# 6.0.

Null Conditional Operator
For a long time (over 4 years) now I’ve been complaining about C# lacking a terse way to handle null objects. In the past, if I wanted to access an object’s member, I had to check if the object was null first. The language had syntax that used “??” to provide a default value when an object was null but it did not help when trying to reference members of the object.

Soon they will have an exciting new way to handle this.
Take a look at the new way of doing this:

Person candidate = null;
var name = candidate?.Name;
var experience = candidate?.ExperienceLevel ?? ExperienceLevel.Senior;

This new “?” operator tests the object for null before calling it’s member. If it is null, then null is returned. It does not cause an object reference exception.

Property Initializers
I often use the “prop” code snippet to insert properties into my classes. It inserts the following code:

public int MyProperty { get; set; }

I do this so often that one of the main reasons I declare private member variables in my classes is to set a default value:

private int myVar;

public int MyProperty
get { return myVar; }
set { myVar = value; }

With new property initializer syntax, this can all be done on one line:

public string Name { get; set; } = “John Doe”

String Interpolation
The old way of concatenating variable values into a string was simple enough:

var y = “world”;
var x = String.Format(“hello {0}”, y);

Microsoft is introducing a new way to place dynamic values into a string. I find it more readable and it reminds me of more modern languages:

var y = “world”;
var x = $”hello {y}”;

Once Visual Studio 2015 with C# 6.0 is released, we will definitely be incorporating these changes into our software development and design. Stay tuned…

Start typing and press Enter to search