A project I'm working on often has lists within lists within lists etc. The original author often uses complicated linq expressions, but when adapting them I mostly get hopelessly bogged down and resort to foreach's which makes me feel like a lesser being (joke). With an expression such as the following, what would the equivalent Linq expression be, and would you bother taking the time to make it, instead of the 'easy' foreach option.
var participantList = new List<string>();
foreach (var community in communities)
{
foreach (var tournament in community.Tournaments)
{
foreach (var round in tournament.Rounds)
{
foreach (var match in round.Matches)
{
if (match.Home.ParticipantId.IsNotNull())
{
participantList.Add(match.Home.ParticipantId);
}
if (match.Away.ParticipantId.IsNotNull())
{
participantList.Add(match.Away.ParticipantId);
}
}
}
}
}