小编wha*_*vAR的帖子

为什么.NET 4.6特定代码在针对框架的旧版本时编译?

我有一个针对旧版.NET Framework(.NET 4.5.2)的项目.我安装了Visual Studio 2015(因此我的机器上安装了.NET 4.6).我注意到如果我使用.NET 4.6/C#6中发布的C#语言功能,它仍会编译.如果我的项目的目标框架是<.NET 4.6,那么这不应该编译:

    public string MyExpressionBodyProperty => "1";

    //auto properties are new in C# 6
    public string MyAutoProperty { get; } = "1";

    private static void MethodThatUsesNameOf(string filename)
    {
        if (filename == null) 
        {
            //nameof was released in C# 6
            throw new ArgumentException("The file does not exist.", nameof(filename));
        }
    }
Run Code Online (Sandbox Code Playgroud)

我怎样才能确保我只使用与我所针对的框架版本一起使用的.NET语言功能?

.net c# c#-6.0 visual-studio-2015 .net-4.6

9
推荐指数
2
解决办法
1999
查看次数

标签 统计

.net ×1

.net-4.6 ×1

c# ×1

c#-6.0 ×1

visual-studio-2015 ×1