How To Enable C# 6.0 / VB 14 In Visual Studio

In this article we will learn how to enable C# 6 / VB 14 settings in Visual Studio.

Microsoft Visual Studio recently introduced C#6, which has many new features like the following:
  
Expression-level features
  •    Null-conditional operators
  •    Index initializers
  •    Extension Add methods
  •    nameof expressions
  •    String interpolation
  •    Overload resolution

Statement-level features

  • Exception filters
  • Await in catch and finally blocks 

Member declaration features

  • Auto-property initializers
  • Parameterless constructors in structs
  • Getter-only auto-properties
  • Expression-bodied function members 

Import features

  • using static 
In this article we will learn how to enable C# 6 / VB 14 in Visual Studio.
 
Open your project and go to Tools, NuGet Package Manager, then click Manage NuGet Packages for solution and search for 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform'
 
Install this in your project first
 
Or you can Install this by writing PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform in your NuGet Package manager Console. 
 
 
 
It will install Microsoft.Net.Compilers 1.0.0 and Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1.
 
 
 
2nd way: Select your project and go to Website tab. Here you just have to click on Enable C# 6 / VB 14,
 
website

It will also do the same thing, install C#6 / VB 14 NuGet Package in your projects.
 
 
 
 
  
 
 
Now open class file and check the following new feature: Auto-property initializers.
 
For that create a property as sin the following. Here you can initialize the property at declaration time. 
  1. public string AddressLine1 { getset; } = "Mumbai";  
 
If you haven't installed C#6 Vb 14 then, it will give you an error, since it is a C# 6 feature.
 
 
 
Hope you like this article, In my next article we will learn new Features of C#.