Search code examples
c#listsublist

Add elements to a sublist of a list in C#


I don't know if this question is too easy but I haven't found anything at the internet to solve this problem.

I have a List of Lists where I add three sublists.

 List<List<DateTime>> myList= new List<List<DateTime>>();

 while (countNeededSubLists != 0)
 {
   myList.Add(new List<DateTime>());
   countNeededSubLists--;
 }

Now I want to simply add a new Date to the sublist which is at index 1 of my list. How to achieve that and what is the correct syntax for that?

Thanks in advance.


Solution

  • myList[1].Add(new DateTime());