我有两个列表
List<string> Name = new List<string>();
List<string> Address = new List<string>();
两个列表都有 30 条数据。我想合并两个列表以获得完整的信息列表,例如
List<string, string> CompleteInformation = new List<string, string>();
另外,如果我想将两个以上的列表合并为一个,该怎么做。
您正在寻找Zip
method:
var CompleteInformation = Name.Zip(Address, (n, a) => new { Address = a, Name = n }).ToList();
为您提供匿名类型实例的列表,具有两个属性:Address
i Name
.
Update
您可以致电Zip
不止一次:
var CompleteInformation
= Name.Zip(Address, (n, a) => new { Address = a, Name = n })
.Zip(AnotherList, (x, s) => new { x.Address, x.Name, Another = s })
.ToList();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)