using System;
using System.Collections.Generic;
namespace ConsoleApplication_C_Sharp
{
class Program
{
static void Main(string[] args)
{
List<List<int>> list = new List<List<int>>();
var rand = new Random();
for (int i = 0; i < 5; i++)
{
List<int> sublist = new List<int>();
int len = rand.Next(1, 13); // sub list size
for (int j = 0; j < len; j++)
{
sublist.Add(rand.Next(1, 10));
}
list.Add(sublist);
}
int totalItems = 0;
foreach (var sublist in list)
{
totalItems += sublist.Count;
}
Console.WriteLine("total Items:" + totalItems);
PrintList(list);
}
static void PrintList(List<List<int>> list)
{
foreach (var sublist in list)
{
foreach (var n in sublist)
{
Console.Write(n + " ");
}
Console.WriteLine();
}
}
}
}
/*
run:
total Items:36
1 5 7 8 1 3
7 2 9 4 2 1 8 2 7 4 5
1 2 2 3
9 2 7 7 8 9 3 9
6 9 3 5 3 5 8
*/