C# 在C语言中将元素添加到列表的子列表中#
我不知道这个问题是否太简单,但我还没有在互联网上找到任何解决这个问题的方法 我有一个列表列表,其中添加了三个子列表C# 在C语言中将元素添加到列表的子列表中#,c#,list,sublist,C#,List,Sublist,我不知道这个问题是否太简单,但我还没有在互联网上找到任何解决这个问题的方法 我有一个列表列表,其中添加了三个子列表 List<List<DateTime>> myList= new List<List<DateTime>>(); while (countNeededSubLists != 0) { myList.Add(new List<DateTime>()); countNeededSubLists--; }
List<List<DateTime>> myList= new List<List<DateTime>>();
while (countNeededSubLists != 0)
{
myList.Add(new List<DateTime>());
countNeededSubLists--;
}
List myList=new List();
while(countneededsublist!=0)
{
添加(新列表());
需要计数的子列表--;
}
现在我只想在列表的索引1处的子列表中添加一个新日期。如何实现这一点,正确的语法是什么
提前谢谢 我建议您始终检查它是否为null,如下所示:
myList[1].Add(new DateTime());
if(!myList.Any())
return;
myList.[1].Add(new DateTime());
哦,我有一个错误。现在它工作了!非常感谢你!