簡體   English   中英

如何使用列表<list<int> &gt; 作為方法中的參數? </list<int>

[英]How to use List<List<int>> as parameter in method?

我沒有找到任何描述或解釋如何將 List< List of int> 作為參數插入方法中的值或 Console.WriteLine()

我已經嘗試了一些變體,但它們似乎都不起作用。 所以我想在這里尋求幫助。

    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;
           }
        }

如果您有一些易於使用的解釋,我願意為您提供知識!

謝謝你的幫助

您應該做的就是創建並填充嵌套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);

...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM