C# 具有自动属性的只读列表

C# 具有自动属性的只读列表,c#,.net,c#-3.0,C#,.net,C# 3.0,有没有一种方法可以通过自动属性实现这一点 private IList<string> List; public IList<String> list { get { return List.ToList().AsReadOnly(); } set { List = value; } } 私有IList列表; 公共IList列表 { 获取{return List.ToList().AsReadOnly();} 设置{

有没有一种方法可以通过自动属性实现这一点

private IList<string> List;
    public IList<String> list
    {
        get { return List.ToList().AsReadOnly(); }
        set { List = value; }
    }
私有IList列表;
公共IList列表
{
获取{return List.ToList().AsReadOnly();}
设置{List=value;}
}

不,没有。自动属性只不过是将简单的返回和赋值语句包装在一个支持字段周围。唯一允许的自定义是可访问性。如果要执行除最基本属性以外的任何操作,则需要使用完整属性

试试这个

私人名单; 公共IList列表 { 获取{return List.ToList().AsReadOnly();} 私有集{List=value;}
}

作为旁注,您应该看看这里的命名指南:。