I have the following:
foreach (var item in selected)
{
var categories = _repo.GetAllDCategories(item);
var result = from cat in categories
select
new
{
label = cat.Name,
value = cat.Id
};
}
The method GetAllDCategories returns a IEnumerable<T>
How to add result to new IEnumerable object that will contain all the items from result for all the selected items in the loop?
Could you not use Concat?
Something like
IEnumerable<string> s1 = new List<string>
{
"tada"
};
IEnumerable<string> s2 = new List<string>
{
"Foo"
};
s1 = s1.Concat(s2);
var result = selected.Select(item=>_repo.GetAllDCategories(item))
.SelectMany(x=>x,(x,cat)=> select new {
label = cat.Name,
value = cat.Id
});
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