Re: A dictionary with many keys for the same value

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Dustin Campbell wrote:
Your stated requirement appears contradictory since your example code
does in fact add two items. Do you mean that you want to "rewrite"
the key (from 0 to 11 in this case)? In that case the technique would
be to remove the item with key == 0, then add it back with key == 11.
This does of course add the item twice, however the resulting
collection.Count would be 1 as desired.

I think he was pretty clear. The example code adds the same item twice but with different keys. He wants the collection to contain two keys pointing to the same item so that the isn't a one-to-one relationship between a key and the item.

Having multiple keys reference the same value is easy enough - but there is an apparent contradiction in wanting the resulting dictionary to have a count of 1. What he really wants the count to indicate, apparently, is the number of unique values in the collection.

Regards,
-rick-
.



Relevant Pages

  • Re: A dictionary with many keys for the same value
    ... Do you mean that you want to "rewrite" ... The example code adds the same item twice but with different keys. ... Dustin Campbell ... Developer Express Inc. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: PIC versus AVR
    ... assembly that I could improve enough to justify the effort to rewrite in ... Once or twice I changed a C expression for better assembly ... experience on AVR targets). ...
    (comp.arch.embedded)
  • Re: HOLY SHIT!
    ... Well, if you were Barbra Streisand, you could recommend he rewrite it to ...
    (rec.arts.theatre.musicals)