C# 2D List

2075 / C# / Списки / 2D List

 

var list = new List<List<int>>();

for (int i = 0; i < 10; i++)
{
  var innerList = new List<int>();
  list.Add(innerList);
}

list[0].Add(1);
list[0].Add(2);
list[0].Add(3);
list[1].Add(4);
list[1].Add(5);
list[1].Add(6);
list[1].Add(7);
list[2].Add(8);
list[2].Add(9);

for (int i = 0; i < list.Count; i++)
{
  for (int j = 0; j < list[i].Count; j++)
  {
    Console.Write(list[i][j] + " ");
  }
  Console.WriteLine();
}

1 2 34 5 6 7

8 9

List<Tuple<int, int>> list = new List<Tuple<int, int>>();
list.Add(new Tuple<int, int>(1, 2));
list.Add(new Tuple<int, int>(3, 4));
list.Add(new Tuple<int, int>(5, 6));
for (int i = 0; i < list.Count; i++)
{
  Console.Write(list[i].Item1 + " " + list[i].Item2 + "\n");
}

1 23 4

5 6