这段代码
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/