How can I do this using LINQ?
var prop = new List<EventProposal>();
foreach (var eventProposal in @event.Proposals)
foreach (var service in eventProposal.Services)
{
if (!string.IsNullOrEmpty(service.LongDescription))
{
prop.Add(eventProposal);
break;
}
}
Any idea?
Thanks in advance
Extension method syntax:
Or query:
NOTE
The logic in your example may not be what you intended; as it stands, it will only add the item if the first
Servicehas a non-emptyLongDescription(because thebreakis outside theif, so it will break on the first item regardless of whether or not it fits the condition). The logic above is assuming that the example is wrong and you want to add it if any of them have a non-emptyLongDescription.If, however, that is what you want, then try this: