C#C
C#4y ago
becquerel

Idiomatic LINQ way to access both object and an object's property? [Answered]

var list = new List<string>();

foreach (Item item in items)
{
  foreach (string thing in item.Things)
  {
    list.Add($"{thing} + {item.OtherProperty}");
  }
}

return list;


I'd like to do this with LINQ. Normally I would use .Select(), but if the inner operation needs both an object (item) and an inner property (thing), I don't know of a clean way to do it. I can .Select() into a tuple containing both items, but this is really ugly. Any idea?
Was this page helpful?