I'm using the following code which works:
IEnumerable<Tag> CreateTags()
{
var suppliers = SupplierQuery.MatchTerms(Min, Max);
foreach (var item in suppliers)
{
var text = item.Name;
var route = PageRoute.GetSupplierRoute(item.Name);
yield return new Tag(text, route);
}
}
I've been trying to chain these 2 statments together using a IEnumerable.ForEach extension method, like this:
IEnumerable<Tag> CreateTags()
{
var suppliers = SupplierQuery.MatchTerms(Min, Max)
.ForEach(x =>
{
yield return new Tag(x.Name, PageRoute.GetSupplierRoute(x.Name));
});
}
However, I get an error - "Yield statement cannot be used inside an anonymous method" - is there any way round this without creating a new List<Tag>
or must they be kept separate?
Thanks in advance.