aybe
aybe

Reputation: 16672

LINQ's Join operation produces zero items

I would like to concatenate items of two lists of same length to an anonymous type, first list objects are of type 'object', second list objects are enumeration values.

Example of their content :

enter image description here

enter image description here

When run, 'list' has no items.

var enumerable = game.Items.Join(game.ItemsElementName, s => s, t => t,
    (item, itemName) => new { Item = item, ItemName = itemName });
var list = enumerable.ToList();

I've tried the second overload of Join() with a predicate but I couldn't implement it as there was hardly anything to compare between an object and an enumeration.

How can merge the contents of these two lists with Join ? if possible at all

Upvotes: 1

Views: 62

Answers (1)

Tim S.
Tim S.

Reputation: 56536

I think you want to use Zip, not Join.

var enumerable = game.Items.Zip(game.ItemsElementName,
               (item, itemName) => new { Item = item, ItemName = itemName });

Upvotes: 5

Related Questions