Introduction
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.
- name of 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
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 a 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.
![nugetpackage]()
It will install Microsoft.Net.Compilers 1.0.0 and Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.1.
![reviewchanges]()
2nd way Select your project and go to the 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.
![enablec#]()
![preview]()
Auto-property initializers
For that, create a property as in the following. Here you can initialize the property at declaration time.
public string AddressLine1 { get; set; } = "Mumbai";
![classlibrary]()
If you haven't installed C#6 Vb 14, then it will give you an error since it is a C# 6 feature.
![c#6vb]()
Hope you like this article; in my next article, we will learn new Features of C#.