2

I have a structure which contains an int value as key and a group of datetime as value.

My question is how to represent such a structure in C#?

I tried Dictionary<int, DateTime[]> but I can't work with the dictionary while adding and removing datetime elements, since the dictionary always requires a different array for each key, which is not practical to be programmed in my application.

2 Answers 2

4

This data structure will work:

IDictionary<int,List<DateTime>> datesById = new Dictionary<int,List<DateTime>>(); datesById.Add(1, new List<DateTime>()); datesById[1].Add(DateTime.Now); 
Sign up to request clarification or add additional context in comments.

Comments

0

Containers in C# have corresponding methods to convert themselves into others

2 Comments

Please explain how this answers the question.
I believe this is referring to, for example, the .ToList() methods and List<T>'s constructor which takes IEnumerable<T>.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.