AddRange to a Collection

后端 未结 8 2198
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 11:41

A coworker asked me today how to add a range to a collection. He has a class that inherits from Collection. There\'s a get-only property of that type t

8条回答
  •  渐次进展
    2020-12-01 12:26

    Remember that each Add will check the capacity of the collection and resize it whenever necessary (slower). With AddRange, the collection will be set the capacity and then added the items (faster). This extension method will be extremely slow, but will work.

提交回复
热议问题