For example I have these two lists:
List<string> firstName = new List<string>();
List<string> lastName = new List<string>();
How can I concatenate firstName[0] and lastName[0], firstName[1] and lastName[1], etc and put it in a new list?
It sounds like you want Zip
from LINQ:
var names = firstName.Zip(lastName, (first, last) => first + " " + last)
.ToList();
(This isn't really concatenating the two lists. It's combining them element-wise, but that's not really the same thing.)
EDIT: If you're using .NET 3.5, you can include the Zip
method yourself - Eric Lippert's blog post on it has sample code.
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