tags:

views:

120

answers:

5

Hello,

I'd like to create a Dictionary, the TKey is a string and the TValue is a List<DateTime>

How can I do this ?

Thanks,

+10  A: 
Dictionary<string, List<DateTime>> dict = new Dictionary<string, List<DateTime>>();

Note that, when adding new items, you need to allocate a new list for the value:

string key; // assuming that's your key
List<DateTime> value;
if (!dict.TryGetValue(key, out value)) {
    value = new List<DateTime>();
    dict.Add(key, value);
}
// value is now always a valid instance
Lucero
+1: I was 2 seconds late... ;o)
Fredrik Mörk
OOOOoooops ..... Am I drunk ? .... probably I tried this, but was probably not exactly this :). Thanks
Kris-I
+1  A: 
Dictionary<string, List<DateTime>>
Charles Bretana
You probably have to be a bit more specific.
Brian Rasmussen
+2  A: 
var dict = new Dictionary<string, List<DateTime>>();

Kindness,

Dan

Daniel Elliott
+1  A: 
Dictionary<string, List<DateTime>> oDictionary;
Stevo3000
+1  A: 

Maybe like:

Dictionary<String, List<DateTime>> myDict = new Dictionary<String, List<DateTime>>();
Frank Bollack