Beispiel #1
0
        static void Main(string[] args)
        {
            var customer = new Customer(1);

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());
            customer.Promote();
            Console.WriteLine(value: customer.Orders.Count);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var customer = new Customer(1);
            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());

            customer.Promote();

            Console.WriteLine(customer.Orders.Count);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var customer = new Customer(1);

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());

            customer.Promote(); //Accidentally initialises the orders making the output 0!

            Console.WriteLine(customer.Orders.Count);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var customer = new Customer(1);

            customer.OrderList.Add(new Order());
            customer.OrderList.Add(new Order());

            customer.Promote();

            System.Console.WriteLine(customer.OrderList.Count);
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            var customer = new Customer(1);

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());

            customer.Promote(); // this clears the orders field out and if you wanna avoid that, that's when you should use the readonly modifier

            Console.WriteLine(customer.Orders.Count);
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            var customer1 = new Customer(121);

            customer1.Orders.Add(new Order());
            customer1.Orders.Add(new Order());

            customer1.Promote();

            Console.WriteLine(customer1.Orders.Count);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var customer = new Customer(1);

            customer.Orders.Add(new Order()); // Add an Order object to a list
            customer.Orders.Add(new Order());

            customer.Promote(); // calling this method modifies the value in the List so we should change Order to read-only variable

            Console.WriteLine(customer.Orders.Count);
        }
Beispiel #8
0
        public static void Main(string[] args)
        {
            var customer = new Customer(1);

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());

            Console.WriteLine(customer.Orders.Count);
            customer.Promote();
            var anotherCustomer = new Customer(2);

            Console.WriteLine(customer.Orders.Count);
        }
        static void Main(string[] args)
        {
            var customer = new Customer(id: 1);

            // Add orders
            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());

            Console.WriteLine("Number of orders: {0}", customer.Orders.Count);

            // This will not work, check Promote method
            customer.Promote();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Customer customer = new Customer(1);

            customer.Orders.Add(new OrderInfo());
            customer.Orders.Add(new OrderInfo());


            customer.Promote();  // if I invoke the Promote() here, then it will reinitize the new Order() List
            // as inside the Promote() method has re-initialize Orders = new List<Orders>()
            // The solution will be to use readonly modifier, this way THE CODE know "Orders" only can invoke ONCE.
            // And gives an error in output

            Console.WriteLine("Counting customer orders: " + customer.Orders.Count);
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            var customer = new Customer(1);

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());
            Console.WriteLine(customer.Orders.Count);
            Console.WriteLine(customer.Id);
            customer.Name = "Sean";
            Console.WriteLine(customer.Name);

            customer.Promote();

            Console.WriteLine(customer.Orders.Count);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello customers!");

            // usethe ctor that assigns an ID
            var customer = new Customer(1);

            // add an order

            customer.Orders.Add(new Order());
            customer.Orders.Add(new Order());

            // Orders is 2
            Console.WriteLine(customer.Orders.Count);

            customer.Promote();
            // if Orders property is NOT set to readonly, Orders is now 0
            // Promote has reset Orders
            Console.WriteLine(customer.Orders.Count);
        }