.net 将字典转换为元组列表

inkz8wg9  于 2023-05-30  发布在  .NET
关注(0)|答案(3)|浏览(220)

如何以最短的方式将字典转换为元组列表(C#)?

Dictionary<long,int> myDico = new Dictionary<long,int>();
IList<Tuple<long, int>> applyOnTree = myDico.Something();
f4t66c6m

f4t66c6m1#

像这样的吗

var list = myDico.Select(x => new Tuple<long, int>(x.Key, x.Value)).ToList();
pcrecxhr

pcrecxhr2#

你可以试试这个

var applyOnTree = myDico.Select(x => Tuple.Create(x.Key, x.Value)).ToList();
xriantvc

xriantvc3#

在隐式元组的情况下:

IList<(long First, int Second)> applyOnTree;

applyOnTree = myDico
   .Select(x => (
      First: x.Key, 
      Second: x.Value))
   .ToList();

相关问题