Thanks for the idea - I wasn't aware of that object, and it looks like
it has uses...

But I don't think this will work for me, since I need different object
types - NVC is for an integer key and a string key, and a string value
only, if I'm reading everything right.  My keys and values can be
various types, and I'll have two values for the same key, instead of
two keys that go together (not sure if that really makes a difference,
but semantically they're different).

On Dec 18, 11:58 am, Cerebrus <[email protected]> wrote:
> I'm sorry, Joe, I did not have time to read through your entire post
> but on reading the first line, the first thing to pop into my mind was
> NVC - NameValueCollection.
>
> This would be appropriate only if my preliminary understanding of your
> scenario is: One Key - Multiple Values.
>
> On Dec 18, 11:40 am, Joe Enos <[email protected]> wrote:
>
> > I've got a need to have a dictionary that returns more than one object
> > for a given key.  There are a few ways of doing this that I could
> > think of, but they weren't really elegant and/or reusable:
>
> > 1) Build a custom container or extended class containing the two
> > objects, then do a regular Dictionary<KeyType, Container>.
> > 2) Have a Dictionary<KeyType, KeyValuePair<ValueType1, ValueType2>>.
>
> > I had an idea for something new, but I don't know if this is
> > necessarily a good idea, or if it's been done before - Please let me
> > know if you have an opinion on this:
>
> > class Trictionary<TKey, TValue1, TValue2>
>
> > It would contain a private Container<TValue1, TValue2> class (that
> > stores the two values) and a Dictionary<TKey, Container>, both behind
> > the scenes.
>
> > It would have methods like the following - basically wrappers around
> > the private Dictionary:
> > Set(TKey key, TValue1 value1, TValue2 value2) {}
> > Remove(TKey key) {}
> > Clear() {}
> > ContainsKey(TKey key) {}
> > Get(TKey key, out TValue1 value1, out TValue2 value2) {}
> > I don't like the idea of "out" parameters, but I couldn't think of any
> > other way to return two values, without resorting to something like an
> > F# Tuple.
>
> > You could iterate and get a series of KeyDualValuePair<TKey, TValue1,
> > TValue2> objects (a custom object, instead of the normal KeyValuePair
> > that you could get by iterating a Dictionary).
>
> > Does anyone have any experience doing something like this?  If you
> > have any ideas or insight into this technique, I'd appreciate it.
>
> > Thanks
>
> > Joe
>
>

Reply via email to