Skip to main content
 首页 » 编程设计

c#之自动实现的属性是否有隐含的集合

2024年01月31日30cloudgamer

<分区>

我原以为对 this.GetProp 的赋值会在编译时失败,因为该属性不支持 set。这段代码用 VS2015 和 NET461 编译得很好。

public class Example 
{ 
    public Example(string val) 
    { 
        this.GetProp = val; 
        this.GetSetProp = val; 
    } 
 
    public string GetProp { get; } 
    public string GetSetProp { get; set; } 
} 

是否有对自动属性中支持字段的隐含私有(private)访问?