Which is faster: clear collection or instantiate new

后端 未结 8 919
遇见更好的自我
遇见更好的自我 2020-12-01 06:26

I have some number of generic lists in my code, that have tens or hundreds elements. Sometimes I need to refill this lists with other objects, so question is: what will be f

8条回答
  •  抹茶落季
    2020-12-01 06:26

    If your objects are value types I'd use Clear() to reduce memory future allocations. Otherwise both approaches are almost identical.

提交回复
热议问题