data.Select(object=> string.Format("<a>{0}</a>", object.LinkText))
.Select(html => string.Format("<div>{0}</div>", html))
.Aggregate((running, next) => running + next);
I have this query which basically turns some objects into html-markup. What I can´t seem to achieve is that the second select should only be run for every (fixed number) 3 elements in the first select. I wan´t my ouput to be something like this:
<div><a>xxx</a><a>yyy</a><a>zzz</a></div>
<div><a>ååå</a>....</div>
Please help me avoid a for-loop!
To group by 3, use this LINQ query:
The output of this program looks like this:
Note how this code uses
string.Joininstead of a slowerAggregate.Of course since you use some other objects instead of strings, you will need to replace
string.Format("<a>{0}</a>", s)withstring.Format("<a>{0}</a>", s.LinkText).