473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Duplicate Key Alternative for Generic Dictionary

I know a Dictionary < TKey, TValue does not allow duplicate keys.

System.Collections.Generic.Dictionary<Guid, Guidtest = new
System.Collections.Generic.Dictionary<Guid, Guid>();
//duplicate key
test.Add(new Guid("00000000-0000-0000-0000-000000000001"), Guid.NewGuid());
test.Add(new Guid("00000000-0000-0000-0000-000000000001"), Guid.NewGuid());
Does anyone know of an alternative generic/collection that would allow the
operation above?

I'm thinking there is C5 option, but figured I'd ask since somebody would
probably know in about 2ms.

Thanks.
Dec 18 '07 #1
3 7036
Does anyone know of an alternative generic/collection that would allow the
operation above?
Yes, you can use the "NameValueCollection".

Dec 18 '07 #2
Well, there's the (immutable) Lookup<TKey,TValueclass in 3.5, but I
can't find it in MSDN2 to find out what the "O" is for the indexer.

Marc

Guid dept1 = new
Guid("00000000-0000-0000-0000-000000000001");
Guid dept2 = new
Guid("00000000-0000-0000-0000-000000000002");
Guid dept3 = new
Guid("00000000-0000-0000-0000-000000000003");

var lookup = new[] {
new {Key=dept1, Value = Guid.NewGuid()},
new {Key=dept1, Value = Guid.NewGuid()},
new {Key=dept1, Value = Guid.NewGuid()},

new {Key=dept2, Value = Guid.NewGuid()},
new {Key=dept2, Value = Guid.NewGuid()},
new {Key=dept2, Value = Guid.NewGuid()},

new {Key=dept3, Value = Guid.NewGuid()},
new {Key=dept3, Value = Guid.NewGuid()},
new {Key=dept3, Value = Guid.NewGuid()}
}.ToLookup(x =x.Key);

foreach (var record in lookup[dept1])
{
Console.WriteLine("{0}: {1}", record.Key,
record.Value);
}
Dec 18 '07 #3
Never mind, that is a string/string collection. Aggggg!

"Rene" <a@b.comwrote in message
news:eF**************@TK2MSFTNGP03.phx.gbl...
>Does anyone know of an alternative generic/collection that would allow
the operation above?

Yes, you can use the "NameValueCollection".

Dec 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Edward Diener | last post by:
Version 2.0 of the Python database API was written over 5 years ago, in 1999. While it has been used successfully by many implementations, there is no generic access into the data dictionary of...
7
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten...
2
by: Jasper Kent | last post by:
I'm trying to do the equivalent of using typedefs with templates in C++ to avoid long instantiation names. I can do this okay: using BigDictionary = System.Collections.Generic.Dictionary<int,...
4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
0
by: Tim_Mac | last post by:
hi, i am able to serialize a normal generic List<> no problem. But when i try to serialize a Dictionary<string,string>, i get an exception as shown below: "The type...
3
by: fstorck | last post by:
Hi, I'm kind of stuck with an serializing / deserializing problem using a generic dictionary holding references to various generic types. It goes as follows: <code> class MyBase :...
2
by: Stephen Costanzo | last post by:
I have: Public Class test Private displayValue As String Private dbType As Integer Property Display() As String Get Return displayValue End Get
2
by: =?Utf-8?B?RGF2aWQgTW9ycmlz?= | last post by:
I am trying to create a nested Dictionary and get an error that seems odd to me. Here is my declaration: private IDictionary<Guid, IDictionary<Guid, string>> myNestedDictionary = new...
9
by: eric | last post by:
I'm trying to define a dictionary whose value is an Generic Action<> delegate private Dictionary<string, List<Action<T>>> Any ideas on to how specify T or a different collection type more...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.