Exemplo n.º 1
0
 public static void FillBox <T>(this Box <T> box, FruitTree <T> tree) where T : Fruit, new()
 {
     do
     {
         try
         {
             box.Add(tree.CreateFruit());
         }
         catch (Exception)
         {
             break;
         }
     } while (true);
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var appleTree = new FruitTree <Apple>();
            var box       = new Box <Apple>(40000);

            box.FillBox(appleTree);

            Console.WriteLine($"box has {box.Count()} apples");
            Console.ReadLine();


            //var box = new Box<Apple>(40);
            //var apple = new Apple { Weight = 35 };
            //var otherApple = new Apple { Weight = 35 };
            //box.Add(apple);
            //box.Add(otherApple);
        }