Pros/cons of using classes and iterating through them instead of using a HashTable? [closed]

StackOverflow https://stackoverflow.com/questions/21448124

質問

In this post, a SO user offers an alternative to Dictionary (the HashTable implementation in C#).

What are the advantages and disadvantages of this approach?

Would performance be a disadvantage? His approach seems to iterate through all the classes to find the correct object but a HashTable would immediately find the value based on the hash function of the key, right?

役に立ちましたか?

解決

A Dictionary requires unique keys, which might be an issue in some cases. Obviously the class provides encapsulation, which is always good, but the Dictionary provides more efficient lookup. It's quite possible to use both though. You use the Dictionary for fast lookup and then the value you get is a class that encapsulates all the related data for the entity, which would probably include the key as well.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top