static void Main(string[] args) { //Create Counter class //which has an integer property //when creating it should have a default value 0 or we can specify it when creating //we can Add(number) to this counter another whole number //or we can Add() without parameters just increasing the counter's value by one //and we can Get() the current value as string //also we can Reset() the value to the initial value Counter count = new Counter(); Console.WriteLine(count.CurrentValue); Console.WriteLine(count.Add(10)); Console.WriteLine(count.Add()); Console.WriteLine(count.Get()); Console.WriteLine(count.Reset()); Console.WriteLine(count.Add()); Console.WriteLine(count.Add()); Console.ReadLine(); }
static void Main(string[] args) { var value = new Counter(); value.Add(5); Console.WriteLine(value.Get()); value.Reset(); Console.WriteLine(value.Get()); Console.ReadLine(); }
static void Main(string[] args) { List <Apple> MyApples = new List <Apple>() { new Apple { colour = "Red" }, new Apple { colour = "Red" }, new Apple { colour = "Red" }, new Apple { colour = "Green" }, new Apple { colour = "Yellow" } }; Counter <Apple> appleCounter = new Counter <Apple>(); appleCounter.Add(MyApples); Counter <Apple> redAppleCounter = new Counter <Apple>(); Func <IEnumerable <Apple>, int> NumRedApples = i => i.Where(a => a.colour == "Red").Count(); redAppleCounter.Add(MyApples, NumRedApples); Box <Apple> boxOfApples = new Box <Apple>(MyApples); List <Box <Apple> > listBox = new List <Box <Apple> >(); listBox.Add(boxOfApples); Cart <Apple> cart = new Cart <Apple>(listBox); Console.WriteLine("Apple Count :"); Console.WriteLine(appleCounter.count); Console.WriteLine("Red Apple Count :"); Console.WriteLine(redAppleCounter.count); Console.WriteLine("Number of things in the box :"); Console.WriteLine(boxOfApples.Count().ToString()); Console.WriteLine("Sum of items in the cart : "); Console.WriteLine(cart.Count().ToString()); Console.ReadLine(); }
static void Main() { // Some things to count var someApples = new List <Apple> { new Apple("Red"), new Apple("Beige"), new Apple("Red"), new Apple("White") }; var boxOfApples = new Box <Apple>(); boxOfApples.Add(new Apple("Blue")); boxOfApples.Add(new Apple("Black")); boxOfApples.Add(new Apple("Red")); var cart = new Cart <Apple>(); cart.Add(boxOfApples); // Some counters var appleColourCounter = new Counter <Apple>(a => a.Colour == "Red"); someApples.ForEach(appleColourCounter.Add); Console.WriteLine(appleColourCounter.Count); // Result should be 2 var appleCounter = new Counter <Apple>(); someApples.ForEach(appleCounter.Add); Console.WriteLine(appleCounter.Count); // Result should be 3 var cartCounter = new Counter <Cart <Apple> >(); cartCounter.Add(cart); Console.WriteLine(cartCounter.Count); // Result is 2 var anythingCounter = new Counter <ICountable>(); someApples.ForEach(anythingCounter.Add); anythingCounter.Add(cart); Console.WriteLine(anythingCounter.Count); // Result is 5 Console.ReadLine(); }
static void Main() { // Some things to count var someApples = new List <Apple> { new Apple(), new Apple(), new Apple() }; var boxOfApples = new Box <Apple>(); boxOfApples.Add(new Apple()); boxOfApples.Add(new Apple()); var cart = new Cart <Apple>(); cart.Add(boxOfApples); // Some counters var appleCounter = new Counter <Apple>(); someApples.ForEach(appleCounter.Add); Console.WriteLine(appleCounter.Count); // Should be 3 var cartCounter = new Counter <Cart <Apple> >(); cartCounter.Add(cart); Console.WriteLine(cartCounter.Count); // Should be 2 (number of apples in the cart in total) var anythingCounter = new Counter <ICountable>(); someApples.ForEach(anythingCounter.Add); anythingCounter.Add(cart); Console.WriteLine(anythingCounter.Count); // Should be 5 - sum of the above Console.ReadLine(); }