List or BusinessObjectCollection?

后端 未结 18 1193
庸人自扰
庸人自扰 2020-12-23 11:11

Prior to C# generics, everyone would code collections for their business objects by creating a collection base that implemented IEnumerable

IE:

publi         


        
18条回答
  •  清酒与你
    2020-12-23 11:26

    As someone else pointed out, it is recommended not to expose List publicly, and FxCop will whinge if you do so. This includes inheriting from List as in:

    public MyTypeCollection : List
    

    In most cases public APIs will expose IList (or ICollection or IEnumerable) as appropriate.

    In cases where you want your own custom collection, you can keep FxCop quiet by inheriting from Collection instead of List.

提交回复
热议问题