fork(4) download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class Product {
  6. public int ID;
  7. public int CategoryID;
  8. }
  9.  
  10. public class Test
  11. {
  12. public static void Main()
  13. {
  14. var products = new List<Product>();
  15. products.Add(new Product() { ID = 1, CategoryID = 1 });
  16. products.Add(new Product() { ID = 2, CategoryID = 1 });
  17. products.Add(new Product() { ID = 3, CategoryID = 7 });
  18. products.Add(new Product() { ID = 4, CategoryID = 8 });
  19. products.Add(new Product() { ID = 5, CategoryID = 9 });
  20. products.Add(new Product() { ID = 6, CategoryID = 10 });
  21.  
  22. var catIDs = new[] { 1, 8, 9 };
  23. var ordered = products
  24. .OrderByDescending(p => catIDs.Contains(p.CategoryID))
  25. .ThenBy(p => p.CategoryID);
  26.  
  27. Console.Write(
  28. string.Join(Environment.NewLine,
  29. ordered.Select(p =>
  30. String.Format("ID={0} CatID={1}",p.ID,p.CategoryID)).ToArray()));
  31. }
  32. }
Success #stdin #stdout 0.05s 37168KB
stdin
Standard input is empty
stdout
ID=1 CatID=1
ID=2 CatID=1
ID=4 CatID=8
ID=5 CatID=9
ID=3 CatID=7
ID=6 CatID=10