Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target .Net 4.5 in VS2015 but I am allowed to use C# 6 features?

I am working in VS2015 on a project which targets .Net framework 4.5

In the Build settings the language version is set to 'default'

As I've read, the C# 6 is only added in .Net 4.6, but I AM allowed (at least, the code compiles and runs) to use the string interpolation feature, which I've read is a C# 6 feature.

Now I am confused: am I now compiling for C# 6 / .Net 4.6 or for .Net 4.5 (and how could I check that?)

EDIT

In the comments I see that C# 6 syntax has nothing to do with the .NET framework version. I got the idea from this answer (What are the correct version numbers for C#?) where is said 'C# 6.0 released with .NET 4.6 and VS2015 (July 2015).' so I understood that C# 6 is (somehow) coupled to .NET 4.6

like image 742
Michel Avatar asked Sep 05 '16 08:09

Michel


1 Answers

C# 6 features such as string interpolation are compiler features, not runtime (CLR) features. Therefore, you can use them regardless of what version of .NET you are building against, as long as your compiler supports C# 6.

In Visual Studio 2015 you can control which version of the language you are targeting in Properties => Build tab => Advanced button => Language Version

like image 117
RB. Avatar answered Sep 28 '22 07:09

RB.