Check this (lambda version):
public static void GetDruckerNameAndAnzahl (List<Queue> input)
{
var model = input
.Where(print=> print.LastStatus == "Printed")
.GroupBy(print=> print.PrinterName)
.OrderByDescending(grp=> grp.Count())
.Select(grp=> new
{
PrinterName = grp.Key,
TotalCount = grp.Count(),
})
.ToList();
foreach (var item in model)
{
Console.WriteLine($"{item.PrinterName}:{item.TotalCount}");
}
}
For further details, please see:
Enumerable.OrderByDescending Method (System.Linq) | Microsoft Docs[
^]
Non-lambda version:
var model =
from print in input
where print.LastStatus == "Printed"
group print by print.PrinterName into PrintGroupPrinted
orderby PrintGroupPrinted.Count() descending
select new {...}