Friday, May 6, 2011

read only list with automatic properties

is there a way to do this with automatic properties ?

private IList<string> List;
    public IList<String> list
    {
        get { return List.ToList().AsReadOnly(); }
        set { List = value; }
    }
From stackoverflow
  • No there is not. Automatic properties do little more than wrap simple return and assignment statements around a backing field. The only customization allowed is accessibility. If you want to do anything other than the most basic property, you'll need to use a full property.

  • try this

    private IList List; public IList list { get { return List.ToList().AsReadOnly(); } private set { List = value; } }

0 comments:

Post a Comment