static void Main()
        {
            Payment phone = new Payment("Samsung S6", 3500m);
            Payment monitor = new Payment("Monitor Sony", 149.99m);

            Customer ivan = new Customer("Ivan", "Petrov", "Ivanov", 9305054476, "Borisova 34", "0883-43-43-12",
                "*****@*****.**", new List<Payment>() { phone, monitor }, CustomerType.Regular);

            // correct copy
            Customer ivanCopy = (Customer)ivan.Clone();
            ivanCopy.FirstName = "Ivancho";
            ivanCopy.Payments.Add(new Payment("Car audi A4", 5000m));
            Console.WriteLine(ivan);
            Console.WriteLine(ivanCopy);
            Console.WriteLine("ivanCopy == ivan : {0}", ivanCopy == ivan);
            Console.WriteLine("ivan.Equals(ivanCopy) : {0}", ivan.Equals(ivanCopy));
            Console.WriteLine("Object.ReferenceEquals(ivan, ivanCopy) : {0}", Object.ReferenceEquals(ivan, ivanCopy));
            Console.WriteLine("\n\n");

            // incorrect copy
            ivanCopy = ivan;
            ivan.FirstName = "Ivancho";
            ivanCopy.Payments.Add(new Payment("Car audi A4", 5000m));
            Console.WriteLine(ivan);
            Console.WriteLine(ivanCopy);
            Console.WriteLine("ivanCopy == ivan : {0}", ivanCopy == ivan);
            Console.WriteLine("ivan.Equals(ivanCopy) : {0}", ivan.Equals(ivanCopy));
            Console.WriteLine("Object.ReferenceEquals(ivan, ivanCopy) : {0}", Object.ReferenceEquals(ivan, ivanCopy));

        }
Beispiel #2
0
        static void Main()
        {
            Customer pesho = new Customer("Petyr",
                                          "Antoniev",
                                          "Georgiev",
                                          "7289182732",
                                          "Sofia",
                                          "0921332",
                                          "*****@*****.**",
                                          CustomerType.Diamond);

            pesho.AddPayment(new Payment("Danyk", 200m));
            Customer pesho2 = (Customer)pesho.Clone();

            Console.WriteLine("pesho and pesho2 are equal: " + pesho.Equals(pesho2));
            pesho2.Email = "*****@*****.**";
            Console.WriteLine("pesho and pesho2 are equal: " + pesho.Equals(pesho2));
            Console.WriteLine(pesho.CompareTo(pesho2));
            pesho2.FirstName = "Ivan";
            Console.WriteLine(pesho.CompareTo(pesho2));
        }
        static void Main()
        {
            Payment  hdd   = new Payment("WD HDD 2TB", 189.99m);
            Payment  mouse = new Payment("Mouse", 9.90m);
            Customer geek  = new Customer("Bill", "Gates", 8712013812, Enum.CustomerType.Diamond, hdd, mouse);

            Payment  vacation = new Payment("Vacation", 1250);
            Customer smart    = new Customer("Katya", "Georgieva", "Tomova", 9203131111, Enum.CustomerType.OneTime, "Sofia", null, null, vacation);

            Customer geekCopy = (Customer)geek.Clone();

            geek.AddNewPayment(vacation);
            Console.WriteLine(geek);
            Console.WriteLine(geekCopy);

            Console.WriteLine(geek == smart);
            Console.WriteLine(geek == geekCopy);
            Console.WriteLine(Customer.Equals(geek, geekCopy));
            Console.WriteLine();

            Customer[] customers = new[] { geek, geekCopy, smart };
            Array.Sort(customers);
            Console.WriteLine(string.Join("\n", customers.ToList()));
        }
Beispiel #4
0
 public static bool operator ==(Customer a, Customer b)
 {
     return(Customer.Equals(a, b));
 }
        private static void Main()
        {
            var pizza   = new Payment("Pizza", 5);
            var coffee  = new Payment("Coffee", 2);
            var croason = new Payment("Croason", 1);

            var customerA = new Customer("Noumi", "Vi", "Chu", "8809023456",
                                         "str. Ivan Vazov", "0999998999", "*****@*****.**", CustomerType.OneTime);

            customerA.Payments.Add(pizza);

            var customerB = new Customer("Noumi", "Vi", "Chu", "8809023456",
                                         "str. Ivan Vazov", "0999998999", "*****@*****.**", CustomerType.OneTime);

            customerB.Payments.Add(pizza);

            var customerC = new Customer("Ivo", "Bi", "Rov", "8909023456",
                                         "str. Ivan Bujorv", "0999998988", "*****@*****.**", CustomerType.Diamond);

            var customerD = new Customer("Noumi", "Vi", "Chu", "8809023456",
                                         "str. Ivan Vazov", "0999998999", "*****@*****.**", CustomerType.OneTime);

            customerD.Payments.Add(coffee);
            customerD.Payments.Add(croason);

            var customerE = new Customer("Noumi", "Vi", "Chu", "9809023456",
                                         "str. Ivan Vazov", "0999998999", "*****@*****.**", CustomerType.OneTime);

            var customerF = new Customer("Galina", "Vi", "Chu", "8809023456",
                                         "str. Ivan Vazov", "0999998999", "*****@*****.**", CustomerType.OneTime);


            Console.WriteLine("customerA == customerB: " + customerA.Equals(customerB)); // True
            Console.WriteLine("customerA == customerC: " + customerA.Equals(customerC)); // False
            Console.WriteLine("customerA == customerD: " + customerA.Equals(customerD)); // False
            Console.WriteLine("customerA == customerB: {0}", customerA == customerB);    // True
            Console.WriteLine("customerA == customerC: {0}", customerA == customerC);    // False
            Console.WriteLine("customerA != customerC: {0}", customerA != customerC);    // True
            Console.WriteLine("customerA != customerD: {0}", customerA != customerD);    // True
            Console.WriteLine();

            var hashCustomers = new HashSet <Customer> {
                customerA, customerB, customerC, customerD
            };

            foreach (var customer in hashCustomers)
            {
                Console.WriteLine(customer); //customerA, customerC, customerD
            }

            var clone = customerA.Clone();

            Console.WriteLine("clone == customerA: {0}", clone == customerA); //True
            Console.WriteLine("clone == customerB: {0}", clone == customerB); //True
            Console.WriteLine("clone == customerC: {0}", clone == customerC); //False

            Console.WriteLine();

            var customers = new List <Customer>()
            {
                customerA, customerB, customerC, customerD, customerE, customerF
            };

            customers.Sort();
            foreach (var customer in customers)
            {
                Console.WriteLine(customer.FirstName + " => " + customer.Id);
            }
        }