Creating a List of Lists in C#

后端 未结 5 1085
梦谈多话
梦谈多话 2020-12-01 03:21

I seem to be having some trouble wrapping my head around the idea of a Generic List of Generic Lists in C#. I think the problem stems form the use of the

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 04:05

    A quick example:

    List> myList = new List>();
    myList.Add(new List { "a", "b" });
    myList.Add(new List { "c", "d", "e" });
    myList.Add(new List { "qwerty", "asdf", "zxcv" });
    myList.Add(new List { "a", "b" });
    
    // To iterate over it.
    foreach (List subList in myList)
    {
        foreach (string item in subList)
        {
            Console.WriteLine(item);
        }
    }
    

    Is that what you were looking for? Or are you trying to create a new class that extends List that has a member that is a `List'?

提交回复
热议问题