.Net 2015 and some new features in C# 6.0


So Microsoft just announced the release of .Net 2015 which includes a new version of the core runtime, a new Version of Visual Studio (named 2015 at present) and ASP.Net 5.

net2015

Open Source

Microsoft has really been changing lately in terms of their outlook towards open source and community engagement and it’s starting to show in each new release of .Net.

Scott Hanselman gives a good account of .Net 2015 and their attitude towards open source in his blog post here. So I recommend checking that out.

All the open source goodness is happening over on the .Net Foundation GitHub site, so if your interested in keeping up to date with the latest additions then go check that out.

C# 6.0

Also within the Visual Studio 2014 timeframe will be the release of C# 6.0 that gives the C# language some convenient features. Some of notable ones are

  • Lambda expression bodies which allow you to basically define a method within a class using a lambda expression instead of a full method body. I like this as it will help to keep class definitions clean and concise.
  • Auto properties that support getters only.
  • Being able to call static methods without their class name prefix. Not sure I like this one too much and I prefer to be a bit more explicit with my calling conventions for readability.
  • Index initializers.
  • Null-conditional operators (Elvis operator :))
  • Nameof operator
  • Exception filters (at last)
  • Await in catch and finally blocks.

You can see a full explanation of the features by Mads Torgensen in this video here.

I have also outlined some of the features in the code block below


using System.Math;

 class Program
 {
     /// <summary>
     /// Getter only auto properties.
     /// </summary>
     public int Number1 { get; }
     public int Number2 { get; }

     static void Main(string[] args)
     {
         // Calling static methods without class prefix.
         Console.WriteLine(Sqrt(9));
         NullConditionalOperators();
     }

     /// <summary>
     /// Lambda expression bodies
     /// </summary>
     /// <returns></returns>
     public int TestAdd() => this.Number1 + this.Number2;

     /// <summary>
     /// Null conditional operators.
     /// </summary>
     public static void NullConditionalOperators()
     {
         string[] testArray = { "1", "2", null};

         // Tests for null value
         Console.WriteLine(testArray?[2]?.ToString());
     }

     /// <summary>
     /// Exception filters
     /// </summary>
     public static void ExceptionFilters(List<int> args)
     {
         try
         {
              Console.WriteLine(args[1]);
         }
         catch (Exception exception) if (exception.InnerException != null)
         {
              // Filtered exception
         }
     }
 }

Trying it out

So you probably want to try out all this new goodness yourself.  Well the easiest way if you have an Azure account is to provision and instance of the VS2015 VM image from the VM gallery and you will be setup with a Windows environment win Visual Studio 2015 installed.

VS2015Azure

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