问题
I have a data like in (string , int) pair. How to store this data in collection object. Both values can be duplicate. Which collection object should i use??
EDIT: How can i access elements separately..??
回答1:
You can use List<KeyValuePair<string,int>>.
This will store a list of KeyValuePair's that can be duplicate.
回答2:
You can use List<KeyValuePair<string, int>> if you want to add & remove items, or KeyValuePair<string, int>[] if the number of items is known
回答3:
If you want to avoid repeating the key for multiple values you can use Dictionary<string, List<int>>.
来源:https://stackoverflow.com/questions/1927589/storing-duplicate-key-value-pairs-in-c-sharp