Ejemplo n.º 1
0
        public void addOrderItems()
        {
            var order = new Order();
            var orderItem = new OrderItem("Volvo XC90");
            var anotherOrderItem = new OrderItem("Mazda 6");

            order.addOrderItem(orderItem);
            order.addOrderItem(anotherOrderItem);

            int itemCount;
            var items = order.getOrderItems(out itemCount);
            Assert.AreEqual(2, itemCount);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var carOrder = new Order();
            var carItem = new OrderItem("Audi B4");
            var alternativeCarItem = new OrderItem("Mitsubishi Lancer");
            var orderItemProcessor = new OrderItemProcessor();

            //return multiple results from function using out

            carOrder.addOrderItem(carItem);

            int carItemCount;
            var orderItems = carOrder.getOrderItems(out carItemCount);

            Console.WriteLine($"Order item count is {carItemCount}", carItemCount);

            //swap two OrderItem instances using ref

            printCarTitles("Before swap:", carItem.Title, alternativeCarItem.Title);
            orderItemProcessor.swapOrderItems(ref carItem, ref alternativeCarItem);
            printCarTitles("After swap:", carItem.Title, alternativeCarItem.Title);

            //duplicateOrderItem receives a copy of object reference. original object does not change

            var duplicateCarItem = orderItemProcessor.duplicateOrderItem(carItem);
            var isSameObject = carItem.Equals(duplicateCarItem);

            printCarComparisonResut(isSameObject, carItem.Title, duplicateCarItem.Title);
        }