Best practice: How to expose a read-only ICollection

前端 未结 7 1748
礼貌的吻别
礼貌的吻别 2020-12-16 02:39

I have an ICollection called foos in my class which I want to expose as read-only (see this question). I see that the interface defines a

7条回答
  •  不知归路
    2020-12-16 03:05

    Return a T[]:

    private ICollection items;
    
    public T[] Items
    {
        get { return new List(items).ToArray(); }
    }
    

提交回复
热议问题