Declare a 2D List in C#
To declare a Multidimensional List in C# wecan declare a list of lists with theList>
notation in C# as there is no built-in method to declare a multidimensional list in C#. Once it's declared you can declare then sub lists and add them to main list.Example
using System;
using System.Collections.Generic;
public class Client
{
public static void Main()
{
List<List<int>> my2dList = new List<List<int>>();
List<int> list1 = new List<int>();
list1.Add(1);
list1.Add(2);
my2dList.Add(list1);
List<int> list2 = new List<int>();
list2.Add(3);
list2.Add(4);
my2dList.Add(list2);
}
}