Returning two lists in C#

后端 未结 6 1456
清歌不尽
清歌不尽 2020-12-06 19:06

I have been researching this for a while now, and am still unsure on how to implement and what is the best way to return two lists from a separate method?

I know the

6条回答
  •  不思量自难忘°
    2020-12-06 19:33

    If you are using later version of .NET and C# then simply use tuples (you may need to Install-Package "System.ValueTuple")

    public static void Method1()
    {
        int[] array1 = { };
        int number1 = 1;
        (List listA, List listB) = Method2(array1, number1);
    }
    
    public static (List, List) Method2(int[] array, int number)
    {
        List list1 = new List();
        List list2 = new List();
    
        return (list1, list2); //<--This is where i need to return the second list
    }
    

提交回复
热议问题