C# Dictionary with two Values per Key?

前端 未结 10 1302
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 17:36

I have a situation in code where a Dictionary seemed like the best idea - I need a collection of these objects and I need them to be acces

相关标签:
10条回答
  • 2020-12-13 18:02

    Doesn't this work for ya?

    Dictionary<string, List<string>>
    

    Or you could use a Tuple and have a dictionary of that:

    Dictionary<string, Tuple<string, bool>>
    
    0 讨论(0)
  • 2020-12-13 18:02

    Another idea is to store the boolean in a separate data structure, e.g. a HashSet.

    0 讨论(0)
  • 2020-12-13 18:04

    Tuple is always a good solution. Furthermore in an object oriented approach, always favour composition over inheritance. Construct a composite object doing the grouping. Simply. I think you are covered with some nice and clean solutions here, from fellow stackoverflow'ers. :)

    0 讨论(0)
  • 2020-12-13 18:09

    In .NET4, you could use (unchecked): Dictionary<string, Tuple<bool,string>>

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