Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. public static void PrintBooksByAuthorAndTotalPrice(Library library)
  2. {
  3.  
  4. // group books in library by author, then order them descending, by their total price (using .Sum())
  5. // and finaly order them by author’s name lexicographically
  6. foreach (var book in library.Books
  7. .GroupBy(b => b.Autor)
  8. .OrderByDescending(x => x.Sum(p => p.Price))
  9. .ThenBy(k => k.Key))
  10. {
  11. Console.WriteLine($"{book.Key} -> {book.Sum(p => p.Price):f2}");
  12. }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement