fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApplication1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var allProducts = new List<Product>
  12. {
  13. new Product() {Name = "Cornflakes", Price = 100},
  14. new Product() {Name = "Cornflakes", Price = 200},
  15. new Product() {Name = "Rice Krispies", Price = 300},
  16. new Product() {Name = "Cornflakes", Price = 400}
  17. };
  18.  
  19. var products = allProducts.Where(w => (!allProducts.Any(l=>l.Name.Equals(w.Name) && l != w)));
  20.  
  21. foreach (Product product in products)
  22. {
  23. Console.WriteLine("Name: {0}, Price: {1}", product.Name, product.Price);
  24. }
  25.  
  26. }
  27.  
  28. public class Product
  29. {
  30.  
  31. public string Name { get; set; }
  32. public decimal Price { get; set; }
  33. }
  34. }
  35. }
Success #stdin #stdout 0.03s 37056KB
stdin
Standard input is empty
stdout
Name: Rice Krispies, Price: 300