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;
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()
.Select()
, but if the inner operation needs both an object (
item
item
) and an inner property (
thing
thing
), I don't know of a clean way to do it. I can
.Select()
.Select()
into a tuple containing both items, but this is really ugly. Any idea?