Timeline for answer to Dictionary - one key, many values by mbx
Current License: CC BY-SA 4.0
Post Revisions
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 10, 2021 at 1:57 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Second iteration.
|
| Nov 8, 2021 at 5:04 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Active reading [<https://en.wikipedia.org/wiki/.NET_Framework> <https://en.wikipedia.org/wiki/Language_Integrated_Query> <https://en.wikipedia.org/wiki/Microsoft_Developer_Network>].
|
| Jul 3, 2018 at 10:01 | comment | added | mbx |
@user3613932 You mean the first list in the full example, right? This is just boiler plate to show the usage of ToLookup and ILookup vs the Dictionary based implementation.
|
|
| Jul 3, 2018 at 2:59 | comment | added | user3613932 |
@mbx I agree with the correctness and feasibility of your approach. With the list approach, there is an implicit assumption in your answer i.e. the collection of values per key is small, and with this assumption in mind, your answer seems appropriate. However, from a readability perspective, if I use something off the shelf to maintain uniqueness in the collection (set) then I would argue it is more readable as the interfaces/API are clear, and even the class HashSet gives a very clear signal to the reader of my code (they don't have to go into my implementation to see what I am doing).
|
|
| Jun 29, 2018 at 14:39 | comment | added | mbx |
@user3613932 Not the point of my answer. If you want to enforce uniqueness for values, just .Distinct() them before creating the lookup. If you need multisets or keep items ordered or indexed a list seems reasonable.
|
|
| Jun 27, 2018 at 23:19 | comment | added | user3613932 |
Suppose key and values are both of type string then why not Dictionary<string, HashSet<string>> instead of Dictionary<string, List<string>>? List cannot guarantee uniqueness within the value collection for a given key but a set can.
|
|
| Aug 24, 2017 at 6:08 | history | edited | mbx | CC BY-SA 3.0 |
remark on immutability - again (see: https://meta.stackoverflow.com/q/355566/303290 )
|
| May 23, 2017 at 10:31 | history | edited | URL Rewriter Bot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
| Jun 8, 2012 at 11:30 | history | edited | mbx | CC BY-SA 3.0 |
added quote of msdn
|
| Jun 8, 2012 at 9:18 | history | edited | mbx | CC BY-SA 3.0 |
added example
|
| Jun 7, 2012 at 15:59 | history | answered | mbx | CC BY-SA 3.0 |