Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an alternative to Dictionary/SortedList that allows duplicates? [duplicate]

Tags:

Possible Duplicate:
C# Sortable collection which allows duplicate keys

Basically I'd like to make a Dictionary work with duplicate keys without going into custom comparer implementations. There is an idea of:

  Dictionary<key, List<value>> 

but it still has some overhead. I wish Dictionary had "AllowDuplicates".

like image 203
Sedat Kapanoglu Avatar asked Feb 16 '09 00:02

Sedat Kapanoglu


People also ask

Can sorted dictionary have duplicate keys?

In SortedDictionary, the key must be unique. Duplicate keys are not allowed. In SortedDictionary, the keys are immutable and cannot be null. In SortedDictionary, the value can be null when the type of the value is of reference type.

Can you have duplicates in a dictionary C#?

In Dictionary, key must be unique. Duplicate keys are not allowed if you try to use duplicate key then compiler will throw an exception. In Dictionary, you can only store same types of elements. The capacity of a Dictionary is the number of elements that Dictionary can hold.

Can key value pair have duplicate keys?

You can use List<KeyValuePair<string,int>> . This will store a list of KeyValuePair 's that can be duplicate.


1 Answers

If you're using .NET 3.5 then Lookup is probably what you're after.

like image 140
LukeH Avatar answered Sep 27 '22 20:09

LukeH