Should a .NET generic dictionary be initialised with a capacity equal to the number of items it will contain?

前端 未结 6 1923
小鲜肉
小鲜肉 2020-12-17 17:12

If I have, say, 100 items that\'ll be stored in a dictionary, should I initialise it thus?

var myDictionary = new Dictionary(100);
<         


        
6条回答
  •  猫巷女王i
    2020-12-17 17:40

    The initial size is just a suggestion. For example, most hash tables like to have sizes that are prime numbers or a power of 2.

提交回复
热议问题