In the code below, the two lists are joined on Index. But either list could have more items than the other and i just want to join up to the list with the least items and throw the rest out from the other list. So, if list 1 has 5 items and list 2 has 7 items, I want to join both up to item 5, and ignore list 2’s remaining items. (and vice versa)
var joinLbxs = lbxShtCols.Items
.Cast<ListItem>()
.Select((xlFldList, index) => new
{
xlFldList,
tblFldList = lbxSqlTablesCols.Items[index]
});
As @Steven suggested in a comment, if you are using .Net 4.0, use the
Zip()method. If you don’t, you could use MoreLinq to provide the same functionality.Or you could do it yourself (assuming both lists are
IList<T>and have fast indexer):