I have a loop:
<% foreach (User usedBy in discountDto.UsedBy)
{ %>
<%=usedBy.FullName%><br />
<% } %>
that often produces multiple lines with the same name:
Bob Smith
Mark Thomas
Mark Thomas
Steve Jones
I would like to aggregate the multiple lines to a single line followed by an integer representing the number of times that name occurred:
Bob Smith
Mark Thomas (2)
Steve Jones
Please excuse formatting - wrong tools "to hand"...
foreach (User usedBy in discountDto.UsedBy.GroupBy(x => x.FullName))
{
var count = usedBy.Count();
%><%=usedBy.Key%><%
if(count>1) %><%=" (" + count + ")"%><%
%><br />
<% } %>
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