您的位置:首页 > 产品设计 > UI/UE

How to create a List of ValueTuple?

2018-10-17 15:21 561 查看

 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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: