Enabling C# 7.1 and 7.2 features in your .NET code

C# 7.0 has been quickly enhanced with a couple of new features in 7.1 and 7.2. If you start Visual Studio 2017 and try e.g. the new “private protected” access modifier then the compiler may not accept it:

public abstract class Animal
{
	private String privateName = "Private name";
	protected String protectedName = "Protected name";
	protected internal String protectedInternalName = "Protected internal name"; 
	private protected String privateProtectedName = "Private protected name";
	public String publicName = "Public name";
}

If it puts a red line under “private protected” saying that this access modifier combination is not allowed then you’ll know that C# 7.2 has not been enabled yet.

First of all make sure that you have the latest .NET SDK installed on your computer: .NET SDKs for Visual Studio . This is 4.7.1 at the time of writing this post.

Next select the project properties, go to the Build tab and click the Advanced… button:

enable c sharp seven features in visual studio

It opens the build settings window where you can specify the language version in the “Language version” drop down list. By default it will say “C# latest major version (default)”. This is where the problem lies as it resolves to C# 7.0 due to the “major” specification of the option. Change it to “C# latest minor version (latest)”:

Change C sharp language version to latest minor

Alternatively you’ll be able to select one of the specific language versions such as “C# 7.1” as well.

Advertisements

About Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

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

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

Robin Sedlaczek's Blog

Developer on Microsoft Technologies

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET MVC,WEB API, WCF, Entity Framework & AngularJS

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: