c# - Why Does .NET 4.6 Specific Code Compile When Targeting Older Versions of the Framework? -
this question has answer here:
- does c# 6.0 work .net 4.0? 3 answers
i have project targets older versions of .net framework (.net 4.5.2). installed visual studio 2015 (and therefore .net 4.6 on machine). noticed if use c# language features released in .net 4.6/c# 6, still compiles. if project's target framework < .net 4.6, shouldn't not compile:
public string myexpressionbodyproperty => "1"; //auto properties new in c# 6 public string myautoproperty { get; } = "1"; private static void methodthatusesnameof(string filename) { if (filename == null) { //nameof released in c# 6 throw new argumentexception("the file not exist.", nameof(filename)); } }
how can ensure i'm using .net language features work framework version i'm targeting?
the .net framework version , c# language version different things. c# 6 language features
public string myautoproperty { get; } = "1"; nameof(filename)
can compiled vs 2015 code targets earlier frameworks.
how can ensure i'm using .net language features work framework version i'm targeting?
if try use .net 4.6 framework feature, appropriate compiler error if targeting earlier framework.
would able deploy code machine did not have .net 4.6?
yes, would. long deployment machine has framework compatible 1 target in vs2015.
Comments
Post a Comment