Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- List<Fruit> fruitList = new List<Fruit>();
- fruitList.Add(new Fruit() { Name = "Apple", Active = false });
- fruitList.Add(new Fruit() { Name = "Orange", Active = false });
- fruitList.Add(new Fruit() { Name = "Strawberry", Active = false });
- Fruit.ApplyUpdate(fruitList);
- }
- }
- public class Fruit
- {
- public string Name { get; set; }
- public bool Active { get; set; }
- public List<FruitSupplier> Suppliers { get; set; }
- public Fruit()
- {
- this.Suppliers = new List<FruitSupplier>();
- }
- public static void ApplyUpdate(List<Fruit> fruitList)
- {
- Parallel.ForEach(fruitList, fruit =>
- {
- //do some processing and set the active property for example
- if (fruit.Name != "Apple")
- fruit.Active = true;
- Parallel.ForEach(fruit.Suppliers, fruitSupplier =>
- {
- //do some processing for the suppliers
- fruitSupplier.Name = "Fruits R Us";
- });
- });
- }
- }
- public class FruitSupplier
- {
- public string Name {get;set;}
- public string Country {get;set;}
- }
Add Comment
Please, Sign In to add comment