Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add duplicate keys to dictionary<string,string>

Tags:

c#

dictionary

how to add duplicate keys to dictionary

i.e i have already added the key,value pair as rollno,1 but i need to add the same parameter to the dictionary,but it is not allowing to add. how to add duplicated keys/repeated key in dictionary .

or any other choice.. any idea???

like image 347
Innova Avatar asked Jul 02 '26 14:07

Innova


2 Answers

That doesn't make sense, if you added duplicate keys to the dictionary, how would it be able to find which one you want when you look them up?

Possibly you're looking for something like a List< KeyValuePair < T, T > >? Where you could store a list of pairs rather than an actual dictionary.

like image 198
Hans Olsson Avatar answered Jul 05 '26 04:07

Hans Olsson


Check out this:

What is the point of Lookup<TKey, TElement>?

You can use the Lookup class to help you create collections with duplicates keys.

like image 24
Jason Evans Avatar answered Jul 05 '26 04:07

Jason Evans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!