fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. private static List<Product> products;
  8.  
  9. public static void Main()
  10. {
  11. // your code goes here
  12. products = new List<Product>()
  13. {
  14. new Product{ ProductCategoryId=1, ProductDepartmentId=1, sections="1"},
  15. new Product{ ProductCategoryId=2, ProductDepartmentId=2, sections="2"},
  16. new Product{ ProductCategoryId=3, ProductDepartmentId=3, sections="3"}
  17. };
  18.  
  19. var prods = GetProducts(2);
  20. Console.WriteLine("ProductCount: {0}", prods.Count());
  21. }
  22.  
  23. public static IEnumerable<Product> GetProducts(
  24. int? productDepartmentId = null,
  25. int? productCategoryId = null,
  26. IEnumerable<int?> productCategoryIds = null,
  27. IEnumerable<string> sections = null)
  28. {
  29. var retList = (from obj in products
  30. where (productDepartmentId == null || obj.ProductDepartmentId == productDepartmentId) &&
  31. (productCategoryId == null || obj.ProductCategoryId == productCategoryId) &&
  32. (productCategoryIds == null || productCategoryIds.Contains(obj.ProductCategoryId)) &&
  33. (sections == null || sections.Contains(obj.sections))
  34. select obj).ToList();
  35. return retList;
  36. }
  37. }
  38.  
  39. public class Product
  40. {
  41. public int ProductDepartmentId { get; set; }
  42. public int ProductCategoryId { get; set; }
  43. public string sections { get; set; }
  44. }
Success #stdin #stdout 0.04s 24240KB
stdin
Standard input is empty
stdout
ProductCount: 1