Here is my problem :
I have several server (identified by their names 'Server1', 'Server2'...)
and several message levels ('Information', 'Warning', 'Error'...).
I want for each couple 'server/message level' store the date of the last
message sent. I thougth about a structure like this :
"Server1"/"Information" -> 2008/03/12 14:00:00
"Server1"/"Error" -> 2008/03/11 09:55:00
"Server2"/"Error" -> 2008/02/27 10:11:00
....
In this structure, the key would be a Dictionary<string, string> identifying
the server and the message level. The value would be the DateTime. I know I
could achieve it in an easier way by concatenating the key
("Server1:Information") and using a Dictionary<string, DateTime>. I'm just
wondering if it is possible to use a Dictionary as a key, and how to use it.
"Jon Skeet [C# MVP]" wrote:
> dox <(E-Mail Removed)> wrote:
> > I'm having trouble using Dictionary classe. I want to use a Dictionary as a
> > key for another Dictionary. The following code gives a sample of what I'm
> > talking about.
> >
> > Dictionary myDates = new Dictionary<Dictionary<string, string>, DateTime>();
> >
> > The 'Add' or 'ContainsKey' methods need a Dictionary<string, string> as a
> > (first) parameter, but how to pass this kind of parameter without
> > instanciating another Dictionary<string, string> variable.
>
> What would you want to pass in as the parameter? What kind of key are
> you wanting to add/test?
>
> To be honest, Dictionary<TKey,TValue> makes a fairly unlikely hash key
> - it doesn't override Equals or GetHashCode, so you have no equality
> beyond identity.
>
> Could you give more details about what you're trying to actually
> achieve? What's the end goal?
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> World class .NET training in the UK: http://iterativetraining.co.uk
>