How to create a list of lists in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

class Program
{
    static void Main() {
        List<List<string>> list_list = new List<List<string>>();
        
        list_list.Add(new List<string> { "a", "b", "c" });
        list_list.Add(new List<string> { "c#", "c++", "c", "java" });
        list_list.Add(new List<string> { "php", "python" });

        foreach (List<string> subList in list_list) {
            foreach (string item in subList) {
                Console.WriteLine(item);
            }
            Console.WriteLine();
        }
    }
}



/*
run:

a
b
c

c#
c++
c
java

php
python

*/

 



answered Mar 10, 2021 by avibootz

Related questions

1 answer 187 views
1 answer 206 views
206 views asked Mar 10, 2021 by avibootz
1 answer 121 views
121 views asked Nov 24, 2023 by avibootz
1 answer 184 views
...