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

Home / 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.

Free User-Friendly Software Checklist

The_user-friendly_software_checklist_-_provided_by_unstoppable_software_pdf__page_1_of_4_

In the last ten years, we've created hundreds of SUPER user-friendly applications that our customers LOVE to use. Our secret? We follow these 7 simple guidelines. Sign up to receive your FREE copy of our checklist now.

Powered by ConvertKit

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…

Nathan Stuller
Nathan Stuller

Nathan Stuller is Development Manager and Lead Developer at Unstoppable. He enjoys problem solving for big companies, working in new technologies, and driving our projects to successful completion.

Recommended Posts
Comments
  • Attefa
    Reply

    Hi Nate 🙂
    I came across the website on linked in. I like the blog section and will be visiting the site for new blogs. Thanks!
    Attefa

Leave a Comment

Start typing and press Enter to search

Two cars crashed