I have
Dictionary<string,IEnumerable<string>> pathAndItems = new Dictionary<string,IEnumerable<String>>();
such as
this/is/path/: {hey, ho, lets, go}
another/path/: {hey, hello}
what I want to do is make one IEnumerable with all concatenaded values.
this/is/path/hey, this/is/path/ho, this/is/path/lets, this/is/path/go, another/path/hey, another/path/hello
I can get all in one, but how can I prepend the key to each?
var SL_requirements = SL_requirementsDict.SelectMany(kvp => kvp.Value);
edit: I would like to do it as a LINQ expression rather than loops
There are various ways of skinning this. SelectMany
lets you specify what to do with each (source, projected-element)
pair too, either in a query expression or not:
var query = from pair in dictionary
from value in pair.Value
select pair.Key + "/" + value;
Or in dot notation:
var query = dictionary.SelectMany(kvp => kvp.Value,
(kvp, value) => kvp.Key + "/" + value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With