Which is faster/more efficient: Dictionary or Dictionary?

后端 未结 4 1026
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 16:27

Are enum types faster/more efficient than string types when used as dictionary keys?

IDictionary or IDict         


        
4条回答
  •  时光取名叫无心
    2021-02-05 16:43

    I would guess that the enum version is faster. Under the hood the dictionary references everything by hashcode. My guess is that it is slower to generate the hashcode for a string. However, this is probably negligibly slower, and is most certainly faster than anything like a string compare. I agree with the other posters who said that an enum is cleaner.

提交回复
热议问题