Пример #1
0
        public static void Main()
        {
            Customer pesho = new Customer(
                1234567890,
                "Petar",
                "Ivanov",
                "Petrov",
                "0884565250",
                "*****@*****.**",
                CustomerType.Diamond,
                new List <Payment>()
            {
                new Payment("Cosmo disk", 124.29m)
            });

            Customer misho = new Customer(
                1023456789,
                "Mihail",
                "Ivanov",
                "Mihailov",
                "0884565253",
                "*****@*****.**",
                CustomerType.Golden,
                new List <Payment>()
            {
                new Payment("Cosmo disk", 124.29m), new Payment("magnitni nakolenki", 45.68m)
            });

            Customer gosho = new Customer(
                1203456789,
                "Georgi",
                "Borisov",
                "Georgiev",
                "0884565252",
                "*****@*****.**",
                CustomerType.Regular,
                new List <Payment>()
            {
                new Payment("magnitni nakolenki", 45.68m)
            });

            Customer goshoCopy = gosho;

            gosho.FirstName = "Genka";
            Console.WriteLine(gosho);
            Console.WriteLine(goshoCopy);
            Console.WriteLine(goshoCopy == gosho);
            Console.WriteLine(gosho.Equals(goshoCopy));
            Console.WriteLine(Object.ReferenceEquals(gosho, goshoCopy));

            goshoCopy           = (Customer)gosho.Clone();
            goshoCopy.FirstName = "Gosho";
            goshoCopy.Payments.Add(new Payment("soleti", 2.03m));
            Console.WriteLine(gosho);
            Console.WriteLine(goshoCopy);
            Console.WriteLine(goshoCopy == gosho);
            Console.WriteLine(gosho.Equals(goshoCopy));
            Console.WriteLine(Object.ReferenceEquals(gosho, goshoCopy));
        }
Пример #2
0
        public static void Main()
        {
            Customer pesho = new Customer(
                1234567890,
                "Petar",
                "Ivanov",
                "Petrov",
                "0884565250",
                "*****@*****.**",
                CustomerType.Diamond,
                new List<Payment>() { new Payment("Cosmo disk", 124.29m) });

            Customer misho = new Customer(
                1023456789,
                "Mihail",
                "Ivanov",
                "Mihailov",
                "0884565253",
                "*****@*****.**",
                CustomerType.Golden,
                new List<Payment>() { new Payment("Cosmo disk", 124.29m), new Payment("magnitni nakolenki", 45.68m) });

            Customer gosho = new Customer(
                1203456789,
                "Georgi",
                "Borisov",
                "Georgiev",
                "0884565252",
                "*****@*****.**",
                CustomerType.Regular,
                new List<Payment>() { new Payment("magnitni nakolenki", 45.68m) });

            Customer goshoCopy = gosho;
            gosho.FirstName = "Genka";
            Console.WriteLine(gosho);
            Console.WriteLine(goshoCopy);
            Console.WriteLine(goshoCopy == gosho);
            Console.WriteLine(gosho.Equals(goshoCopy));
            Console.WriteLine(Object.ReferenceEquals(gosho, goshoCopy));

            goshoCopy = (Customer)gosho.Clone();
            goshoCopy.FirstName = "Gosho";
            goshoCopy.Payments.Add(new Payment("soleti", 2.03m));
            Console.WriteLine(gosho);
            Console.WriteLine(goshoCopy);
            Console.WriteLine(goshoCopy == gosho);
            Console.WriteLine(gosho.Equals(goshoCopy));
            Console.WriteLine(Object.ReferenceEquals(gosho, goshoCopy));
        }
Пример #3
0
        public static void Main()
        {
            Customer pesho1 = new Customer("Peter", "Ivanov", "Petrov", "8010201020", "AAA 5", "0888 123 456", "*****@*****.**",
                new List<Payment>{new Payment("Vnoska", 150.99)}, CustomerType.OneTime);

            Customer pesho2 = (Customer) pesho1.Clone();

            Console.WriteLine(pesho1.Equals(pesho2));
            Console.WriteLine(pesho1.CompareTo(pesho2) + "\n");

            pesho2.Id = "8010201021";

            Console.WriteLine(pesho1.Equals(pesho2));
            Console.WriteLine(pesho1.CompareTo(pesho2) + "\n");
        }
Пример #4
0
        static void Main()
        {
            Customer Ivan = new Customer(3, "Ivan", "Petrov", "Goshov", "Sofia, Mladost", "+359-897-687-52", "*****@*****.**", CustomerType.Golden, new List<Payment>() { new Payment("Lenovo", 533), new Payment("Samsung", 789), });
            Customer Petar = new Customer(2, "Petar", "Goshov", "Ivanov", "Sofia, Lulin", "+359-897-534-59", "*****@*****.**", CustomerType.OneTime, new List<Payment>() { new Payment("Acer", 533), new Payment("MSI", 789), });
            Customer Ivan4o = new Customer(1, "Ivan", "Petrov", "Goshov", "Sofia, Iztok", "+359-897-687-49", "*****@*****.**", CustomerType.Diamond, new List<Payment>() { new Payment("Asus", 533), new Payment("HP", 789), });
            Customer IvanCopy = (Customer)Ivan.Clone();

            Console.WriteLine(Ivan + "\n");

            Console.WriteLine(Ivan.Equals(Petar));
            Console.WriteLine(Ivan.Equals(Ivan4o));
            Console.WriteLine(Ivan.Equals(IvanCopy) + "\n");

            Console.WriteLine(Ivan.CompareTo(IvanCopy));
            Console.WriteLine(Ivan.CompareTo(Ivan4o));
        }
Пример #5
0
        static void Main()
        {
            Payment p1 = new Payment("Coffee", 2.53m);
            Payment p2 = new Payment("Tea", 1.41m);
            Payment p3 = new Payment("Beer", 3.78m);
            Payment p4 = new Payment("Cheese", 6.33m);
            Payment p5 = new Payment("Bread", 1.02m);

            IList<Payment> payments1 = new List<Payment> {p1, p2};
            IList<Payment> payments2 = new List<Payment> { p1, p2 };
            IList<Payment> payments3 = new List<Payment> { p2, p3, p4, p5 };
            IList<Payment> payments4 = new List<Payment> { p3, p4 };
            IList<Payment> payments5 = new List<Payment> { p4, p5 };

            Customer pesho = new Customer("Petar", "Dimitrov", "Petrov", 6005121315, "Sofia", "0888-888888",
                "pesho.abv.bg", payments1, CustomerType.Diamond);
            Customer gosho1 = new Customer("Georgi", "Mihajlov", "Georgiev", 7510124567, "Plovdiv", "0777-777777",
                "gosho.abv.bg", payments3, CustomerType.Golden);
            Customer gosho2 = new Customer("Georgi", "Mihajlov", "Georgiev", 7510124567, "Plovdiv", "0777-777777",
                "gosho.abv.bg", payments3, CustomerType.Golden);
            Customer gosho3 = new Customer("Georgi", "Mihajlov", "Georgiev", 6510124567, "Plovdiv", "0777-777777",
                "gosho.abv.bg", payments3, CustomerType.Golden);
            Customer misho = new Customer("Mihail", "Todorov", "Todorov", 5512024567, "Ruse", "0666-666666",
                "email.abv.bg", payments4, CustomerType.OneTime);

            IList<Customer> customers = new List<Customer>
            {
                pesho, gosho1, gosho2, gosho3, misho
            };

            Console.WriteLine("Print HashCodes:");
            foreach (var customer in customers)
            {
                Console.WriteLine(customer.GetHashCode());
            }
            Console.WriteLine();

            Console.WriteLine("Print equalities: ");
            Console.WriteLine(pesho.Equals(gosho1));
            Console.WriteLine(pesho == gosho1);
            Console.WriteLine(gosho1 == gosho2);
            Console.WriteLine(gosho1 != gosho3);
            Console.WriteLine();

            Console.WriteLine("Prnt cloning:");
            Customer cloning = (Customer)pesho.Clone();
            Console.WriteLine("cloning == pesho? {0}", cloning == pesho);
            Console.WriteLine("Cloning:\n" + cloning);
            Console.WriteLine("Pesho:\n" + pesho);
            cloning.FirstName = "Joro";
            Console.WriteLine("Cloning after changing first name:\n" + cloning);
            Console.WriteLine("Pesho:\n" + pesho);

            Console.WriteLine("Compare to:");
            Console.WriteLine("gosho1 compareTo gosho2: {0}", gosho1.CompareTo(gosho2));
            Console.WriteLine("gosho1 compareTo gosho3: {0}", gosho1.CompareTo(gosho3));
            Console.WriteLine("gosho3 compareTo gosho1: {0}", gosho3.CompareTo(gosho1));
        }
Пример #6
0
        public static void Main()
        {
            try
            {
                Customer stefan = new Customer("Stefan", "Ivanov", "Stefanov", "1234567890", "Sofia", "+359888777666", "*****@*****.**", new Payment("VGA", 260.0m), CustomerType.Diamond);

                Customer copyOfStefan = stefan;

                Customer ivan = stefan.Clone() as Customer;
                ivan.FirstName = "Ivan";
                ivan.AddPayment(new Payment("CPU", 354.12m));
                
                Console.WriteLine(stefan);
                Console.WriteLine("Deep copy:\n{0}", ivan);
                Console.WriteLine("Equals (different customers): {0}", stefan.Equals(ivan));
                Console.WriteLine("Compare (different customers): {0}", stefan.CompareTo(ivan));
                Console.WriteLine("Equals (different customers, same reference): {0}", stefan.Equals(copyOfStefan));
                Console.WriteLine("Compare (different customers, same reference): {0}", stefan.CompareTo(copyOfStefan));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        } 
Пример #7
0
        internal static void Main()
        {
            Customer thomas = new Customer("Thomas", "Anderson", "Rodriguez", "123456798", "America", "+1123456789", "*****@*****.**", new List<Payment>() { new Payment("Jacket", 99.99m), new Payment("Jeans", 49.99m) }, CustomerType.Diamond);

            Console.WriteLine("ToString()");          
            Console.WriteLine(thomas);

            Console.WriteLine("Clone()"); 
            Customer copy = thomas.Clone() as Customer;
            Console.WriteLine(copy);

            Console.WriteLine("Is copy deep?");
            copy.FirstName = "Lee";
            copy.Payments = new List<Payment>()
            {
                new Payment("Shoes", 29.99m)
            };
            copy.Id = "123456798";
            Console.WriteLine(copy);
            Console.WriteLine(thomas);

            Console.WriteLine("Equals()"); 
            Console.WriteLine(thomas.Equals(copy));
            Customer third = thomas.Clone() as Customer;
            Console.WriteLine(thomas.Equals(third));

            Console.WriteLine("== and !=");
            Console.WriteLine(thomas == copy);
            Console.WriteLine(thomas != copy);
            Console.WriteLine(thomas == third);
            Console.WriteLine(thomas != third);

            Console.WriteLine("CompareTo()"); 
            Console.WriteLine(thomas.CompareTo(copy));
            Console.WriteLine(thomas.CompareTo(third));
        }
Пример #8
0
        static void Main()
        {
            Customer pesho = new Customer("Pesho", "Peshev", "Peshliyski", 8012213456, "Peshovitza 5", "02/3456789", "*****@*****.**", new List<Payment>(), CustomerType.Regular);
            pesho.Payments.Add(new Payment("Vinkel", 100));
            pesho.Payments.Add(new Payment("Armatura", 150));
            Console.WriteLine(pesho);
            Console.WriteLine("Payments:");
            foreach (Payment item in pesho.Payments)
            {
                Console.WriteLine("- {0} - {1} BGN", item.ProductName, item.Price);
            }
            Console.WriteLine(new string('=', 30));

            Customer gosho = pesho.Clone() as Customer;
            gosho.FirstName = "Gosho";
            gosho.ID = 7704024567;
            gosho.Email = "*****@*****.**";
            gosho.Payments.Add(new Payment("Ankeri", 100));

            Console.WriteLine(gosho);
            Console.WriteLine("Payments:");
            foreach (Payment item in gosho.Payments)
            {
                Console.WriteLine("- {0} - {1} BGN", item.ProductName, item.Price);
            }
            Console.WriteLine(new string('=', 30));

            if (pesho.CompareTo(gosho) > 0)
            {
                Console.WriteLine("Customer is first, compared to the given criteria.");
            }
            else if (pesho.CompareTo(gosho) < 0)
            {
                Console.WriteLine("Customer is last, compared to the given criteria.");
            }
            else
            {
                Console.WriteLine("Customers are equal.");
            }

            Console.WriteLine("First equals second: " + pesho.Equals(gosho));
            Console.WriteLine("First == second: " + (pesho == gosho));
            Console.WriteLine("First != second: " + (pesho != gosho));

            Console.WriteLine("First's hash: " + pesho.GetHashCode());
            Console.WriteLine("Second's hash: " + gosho.GetHashCode());
        }
        static void Main()
        {
            Customer firstCustomer = new Customer(
                "Peter",
                "Petrov",
                "Petrov",
                "8002044445",
                "0885885885",
                "*****@*****.**",
                CustomerType.Regular);

            Customer secondCustomer = new Customer(
                "Ivan",
                "Ivanov",
                "Ivanov",
                "9002042225",
                "0887885884",
                "*****@*****.**",
                CustomerType.Regular);

            Customer thirdCustomer = (Customer)secondCustomer.Clone();

            thirdCustomer.FirstName = "Gosho";
            thirdCustomer.EGN       = "8212122246";

            List <Customer> customers = new List <Customer>()
            {
                firstCustomer, secondCustomer, thirdCustomer
            };

            customers.Sort();

            foreach (var c in customers)
            {
                Console.WriteLine(c);
            }

            Console.WriteLine(secondCustomer);
            Console.WriteLine(thirdCustomer);
            Console.WriteLine(firstCustomer.Equals(secondCustomer));
        }
        static void Main()
        {
            Payment keyboard = new Payment("Keyboard MODECOM", 35m);
            Payment monitor  = new Payment("Monitor Sony", 149.99m);
            Payment glasses  = new Payment("Glasses Alpina", 79.80m);
            Payment shoes    = new Payment("Sport shoes Adidas", 179.99m);
            Payment dog      = new Payment("Husky", 90m);

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

            Customer dancho = new Customer(
                "Yordan",
                "Yordanov",
                "Kirov",
                7305041495,
                "Borisova 55",
                "0883-44-66-92",
                "*****@*****.**",
                new List <Payment>()
            {
                glasses, shoes
            },
                CustomerType.Golden);

            Customer tanq = new Customer(
                "Tatqna",
                "Georgieva",
                "Petrova",
                7402031596,
                "Borisova 35",
                "0889-49-23-67",
                "*****@*****.**",
                new List <Payment>()
            {
                glasses, shoes, dog, monitor
            },
                CustomerType.Diamond);

            // correct copy
            Customer goshoCopy = (Customer)gosho.Clone();

            goshoCopy.FirstName = "Gecata";
            goshoCopy.Payments.Add(new Payment("Car audi A4", 5000m));
            Console.WriteLine(gosho);
            Console.WriteLine(goshoCopy);
            Console.WriteLine("goshoCopy == gosho : {0}", goshoCopy == gosho);
            Console.WriteLine("gosho.Equals(goshoCopy) : {0}", gosho.Equals(goshoCopy));
            Console.WriteLine("Object.ReferenceEquals(gosho, goshoCopy) : {0}", Object.ReferenceEquals(gosho, goshoCopy));
            Console.WriteLine("\n\n\n");

            // incorrect copy
            goshoCopy       = gosho;
            gosho.FirstName = "Goshkata";
            goshoCopy.Payments.Add(new Payment("Car audi A4", 5000m));
            Console.WriteLine(gosho);
            Console.WriteLine(goshoCopy);
            Console.WriteLine("goshoCopy == gosho : {0}", goshoCopy == gosho);
            Console.WriteLine("gosho.Equals(goshoCopy) : {0}", gosho.Equals(goshoCopy));
            Console.WriteLine("Object.ReferenceEquals(gosho, goshoCopy) : {0}", Object.ReferenceEquals(gosho, goshoCopy));
        }
Пример #11
0
        static void Main()
        {
            Payment keyboard = new Payment("Keyboard MODECOM", 35m);
            Payment monitor = new Payment("Monitor Sony", 149.99m);
            Payment glasses = new Payment("Glasses Alpina", 79.80m);
            Payment shoes = new Payment("Sport shoes Adidas", 179.99m);
            Payment dog = new Payment("Husky", 90m);

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

            Customer dancho = new Customer(
                "Yordan",
                "Yordanov",
                "Kirov",
                "7305041495",
                "Borisova 55",
                "0883-44-66-92",
                "*****@*****.**",
                new List<Payment>() { glasses, shoes },
                CustomerType.Golden);

            Customer tanq = new Customer(
                "Tatqna",
                "Georgieva",
                "Petrova",
                "7402031596",
                "Borisova 35",
                "0889-49-23-67",
                "*****@*****.**",
                new List<Payment>() { glasses, shoes, dog, monitor },
                CustomerType.Diamond);

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

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