Storing duplicate key value pairs in C#

别说谁变了你拦得住时间么 提交于 2019-12-19 05:02:49

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!