相关疑难解决方法(0)

为什么自动实现的属性必须同时定义get和set访问器

当我们定义一个属性时

    public string Name {get; set;}
Run Code Online (Sandbox Code Playgroud)

dot net可以使我们的属性代码.但是当我们使用时

    public string Name {get;}
    public string Name {set;}
Run Code Online (Sandbox Code Playgroud)

我们面对

'Hajloo.SomeThing.PropertyName.set' must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.
Run Code Online (Sandbox Code Playgroud)

实际上为什么编译器无法确定属性并自动生成代码?有什么问题?

c# get properties accessor set

32
推荐指数
2
解决办法
2万
查看次数

标签 统计

accessor ×1

c# ×1

get ×1

properties ×1

set ×1