I have two separate lists as:
List<string> keys = new List<string>() { "A", "A", "B","B","C","C" };
List<datetime> dates = new List<datetime>() { 1/1/2000 12:00AM, 1/1/2000 12:30AM, 1/2/2000 12:00AM, 1/2/2000 12:30AM, 5/1/2000 12:00AM, 5/1/2000 12:30AM };
I would like to build a dict<string,List<datetime>>
. Expected output is:
Dict[0] = A, (1/1/2000 12:00AM, 1/1/2000 12:30AM)
Dict[1] = B,(1/2/2000 12:00AM, 1/2/2000 12:30AM)
Dict[2] = C, (5/1/2000 12:00AM, 5/1/2000 12:30AM )
How can I achieve this?
This is how I was approaching it but to no avail:
for (int i = 0; i < keys.Count; i++)
{
var id = keys.ElementAt(i);
for (int j = 0; j < dates.Count; j++)
{
List<DateTime> values;
if (!dict.TryGetValue(id, out values))
{
values = new List<DateTime>();
dict[id] = values;
}
values.Add(dates.GetSampleTimeAt(j));
}
}