So I ran into a
Dictionary<int, int> today at work. This just seemed weird to me because I would have probably just used a
List<int> instead. Is there a difference and would there be a use case where one structure would be preferred over the other?
|show 1 more comment|
You would use a
The immediate example that comes to mind is storing an id column and an int column in a database. For example, if you have a
But really, any time you have two related lists of integers, this could be an appropriate data structure.
Think of the
For example, say you wanted to store an association between a person's age and their height. You could use a
Not a very useful example, but the point is you wouldn't be able to do this as elegantly with a
Which one you will choose should depend on the range of the key values. If your keys in the
If your key values are 100