c# - 在 Visual Studio 2015 中,可以设置只读自动属性并构建它!这是一个错误吗?

标签 c# visual-studio-2015

这段代码

public class Entity
{
    public string First { get; }
    public string Last { get; }
    public Entity()
    {
        this.First = "First name";
        this.Last = "Last name";
    }
}

将在 VS2015 中编译,但 VS2013 给出错误“无法将属性或索引器‘ScottRickman.Entity.First’分配给 -- 它是只读的”

这是 VS2015 中的错误吗?

最佳答案

这是一个新的 feature of C# 6.0 (参见“Getter-only auto-properties”部分)。 VS2015默认使用C#6.0编译器,而VS2013默认使用C#5.0编译器,因此编译时错误只出现在VS2013。

关于c# - 在 Visual Studio 2015 中,可以设置只读自动属性并构建它!这是一个错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33254605/

相关文章:

c# - 需要合并 Dll 并创建单个程序集

wcf - 无法在 Web 服务器上开始调试。底层连接已关闭 : An unexpected error occurred on a send

windows-8 - 在 Visual Studio 2015 中构建 Windows 8 商店应用程序

asp.net-mvc - 禁用 Telerik 脚手架 Visual Studio 模板

c# - 由于 SSL,Web 服务调用在 SQL Clr 代码中失败

c# - 在 SqlBulkCopy 期间更改值

c# - 仅允许 NumericUpAndDown 中的整数值 Mahapp 无法正常工作

c# - 如何在鼠标悬停时创建带有 WPF 边框的淡出过渡效果?

android-emulator - 适用于 Android 的 Visual Studio 2015 RC 模拟器无法启动

c# - 为什么 Visual Studio 2015 Intellisense 不显示任何类、方法等信息?