I believe this foreach
loop will achieve your goal, if I've understood the problem.
It will loop over any element of items
that is a (or is derived from) SubItem
. It will then select all SomeObject.SomeString
strings and add them to the SomeList
.
foreach (var subItem in items.OfType<SubItem>()) {
subItem.SomeList.AddRange(subItem.SomeObject.Select(o => o.SomeString));
}
This is a compilation of suggestions from Panagiotis Kanavos, juharr, and Aluan Haddad.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…