Home > database >  How to use List<List<int>> as parameter in method?
How to use List<List<int>> as parameter in method?

Time:09-06

I haven't found any description or explanation how to insert List< List of int> as parameter with values in method nor to Console.WriteLine()

I have tried some variants, but non of them seems to work. So I'm trying to find help here.

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Result.ListManipulation()));
        //I want to insert 3 Lists and manipulate with them inside the method
        //List<int>{11, 2, 4 };
        //List<int>{4, 5, 6};
        //List<int>{10, 8, -12};
            Console.ReadLine();
        }
    }
        class Result
        {
            public static int ListManipulation(List<List<int>> arr)
            { 
                //Manipulation with those 3 Lists
                return 0;
           }
        }

If You have some easy to use explanation, I'm open for Your knowledge!

Thanks for your help

CodePudding user response:

All you should do is to create and fill the nested List<List<int>>:

...
// You should create a nested List - new List<List<int>>()...
List<List<int>> myList = new List<List<int>>() {
  // ... and fill it line by line 
  new List<int>() { 11, 2,   4 },
  new List<int>() {  4, 5,   6 },
  new List<int>() { 10, 8, -12 },
}; 

int result = ListManipulation(myList);

...
  • Related