How to create a List of ValueTuple?

 ValueTuple需要通过NuGet安装System.ValueTuple

https://docs.microsoft.com/en-us/dotnet/csharp/tuples?view=netframework-4.7.2

https://docs.microsoft.com/en-us/dotnet/api/system.valuetuple?view=netframework-4.7.2

 https://stackoverflow.com/questions/44250462/how-to-create-a-list-of-valuetuple

You are looking for a syntax like this:

List<(int, string)> list = new List<(int, string)>();
list.Add((3, "test"));
list.Add((6, "second"));

You can use like that in your case:

List<(int, string)> Method() => 
    new List<(int, string)>
    {
        (3, "test"),
        (6, "second")
    };

You can also name the values before returning:

List<(int Foo, string Bar)> Method() =>
    ...

And you can receive the values while (re)naming them:

List<(int MyInteger, string MyString)> result = Method();
var firstTuple = result.First();
int i = firstTuple.MyInteger;
string s = firstTuple.MyString;
原文地址:https://www.cnblogs.com/chucklu/p/9804384.html