Initialize a collection within an object?

后端 未结 10 1253
长发绾君心
长发绾君心 2021-02-04 15:03

If an object has a property that is a collection, should the object create the collection object or make a consumer check for null? I know the consumer should not assume, just

10条回答
  •  温柔的废话
    2021-02-04 15:26

    IMO, this is where IEnumerable comes in nicely.

    Personally, I like my 'collection' properties to be initialized to empty lists.

提交回复
热议问题