Storing duplicate key value pairs in C#

前端 未结 3 1078
小蘑菇
小蘑菇 2021-01-07 17:04

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??

相关标签:
3条回答
  • 2021-01-07 17:18

    You can use List<KeyValuePair<string,int>>.

    This will store a list of KeyValuePair's that can be duplicate.

    0 讨论(0)
  • 2021-01-07 17:21

    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

    0 讨论(0)
  • 2021-01-07 17:21

    If you want to avoid repeating the key for multiple values you can use Dictionary<string, List<int>>.

    0 讨论(0)
提交回复
热议问题