I have two Lists
List<string> Name = new List<string>();
List<string> Address = new List<string>();
Both the lists having 30 data. I want to merge both the lists to get a complete Information lists like
List<string, string> CompleteInformation = new List<string, string>();
Also if I want to merge more than two list in one how it can be done.
You're looking for Zip
method:
var CompleteInformation = Name.Zip(Address, (n, a) => new { Address = a, Name = n }).ToList();
Gives you list of anonymous type instances, with two properties: Address
i Name
.
Update
You can call Zip
more then once:
var CompleteInformation
= Name.Zip(Address, (n, a) => new { Address = a, Name = n })
.Zip(AnotherList, (x, s) => new { x.Address, x.Name, Another = s })
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With