Guest User

Untitled

a guest
Feb 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. List<Fruit> fruitList = new List<Fruit>();
  6. fruitList.Add(new Fruit() { Name = "Apple", Active = false });
  7. fruitList.Add(new Fruit() { Name = "Orange", Active = false });
  8. fruitList.Add(new Fruit() { Name = "Strawberry", Active = false });
  9.  
  10. Fruit.ApplyUpdate(fruitList);
  11. }
  12. }
  13.  
  14. public class Fruit
  15. {
  16. public string Name { get; set; }
  17. public bool Active { get; set; }
  18. public List<FruitSupplier> Suppliers { get; set; }
  19.  
  20. public Fruit()
  21. {
  22. this.Suppliers = new List<FruitSupplier>();
  23. }
  24.  
  25. public static void ApplyUpdate(List<Fruit> fruitList)
  26. {
  27. Parallel.ForEach(fruitList, fruit =>
  28. {
  29. //do some processing and set the active property for example
  30. if (fruit.Name != "Apple")
  31. fruit.Active = true;
  32.  
  33. Parallel.ForEach(fruit.Suppliers, fruitSupplier =>
  34. {
  35. //do some processing for the suppliers
  36. fruitSupplier.Name = "Fruits R Us";
  37. });
  38. });
  39. }
  40. }
  41.  
  42. public class FruitSupplier
  43. {
  44. public string Name {get;set;}
  45. public string Country {get;set;}
  46. }
Add Comment
Please, Sign In to add comment