具有自动属性的只读列表

Han*_*sir 0 .net c# c#-3.0

有没有办法用自动属性做到这一点?

private IList<string> List;
    public IList<String> list
    {
        get { return List.ToList().AsReadOnly(); }
        set { List = value; }
    }
Run Code Online (Sandbox Code Playgroud)

Jar*_*Par 10

不,那里没有.自动属性只是在支持字段周围包装简单的返回和赋值语句.唯一允许的自定义是可访问性.如果您想要做除最基本财产以外的任何事情,您将需要使用完整的财产.