Enumerate object List property with Linq?

Let's say I have a class that looks something like:

class Foo { public List<string> Bars; } 

And I have a list of Foo somewhere else:

public void EnumerateFoos(List<Foo> foos) 

And from this list of Foo, I want to enumerate all Bars and do something to them – how can I go about that with Linq? When I write this code:

foreach(var foo in foos) { foreach(var bar in foo.Bars) { Say(bar); } } 

Resharper always tells me that it can be merged into a Linq expression, but I can't see how and my Google searches have been unsuccessful since I'm not exactly sure what I should search for!

Anyone know how to merge this into one Linq expression, so I simply have one (merged) list of strings to enumerate? Will love you forever!

by noobsc2 via /r/csharp

Leave a Reply