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));

        }
Пример #2
0
        static void Main()
        {
            var customer1 = new Customer(
                "Gosho", "Ivanov", "Peshov",
                9302238338,
                "Tsarigradsko Shose 5",
                0886333333,
                "*****@*****.**",
                new List<Payment>
                {
                    new Payment("Beans", 2.50m),
                    new Payment("Toothpaste", 1.20m)
                },
                CustomerType.Regular);

            var customer2 = customer1.Clone();

            customer2.Payments.Add(new Payment("Chewing gum", 0.90m)); // he's unequal to customer1 now

            customer2.FirstName = "Angel"; // he'll come first if you sort the list he's part of
            //customer2.Id = 1111111111; // he'll also come first if his ID comes first

            var customers = new List<Customer> {customer1, customer2};
            customers.Sort(); // when we sort the list, Angel goes first because his name is earlier in the alphabet

            Console.WriteLine(string.Join("\n\n", customers));
        }
Пример #3
0
        static void Main(string[] args)
        {
            Customer one = new Customer("Gosho", "Peshev", "Meshev", 1111111111,"address","0000000000","email",CustomerType.Diamond);

            var two = one.Clone() as Customer;

            Console.WriteLine(two);
            Console.WriteLine(one == two);
            Console.WriteLine(one.CompareTo(two));
        }
Пример #4
0
        public static void Main(string[] args)
        {
            var customer = new Customer("ma", "re", "mi", "1",
                "asdas", "12321", "adsd", new List<Payment>() { new Payment("asds", 12)},
                CustomerType.OneTime);

            var copy = (Customer) customer.Clone();

            Console.WriteLine(customer == copy);
            Console.WriteLine(customer);
            copy.FirstName = "Changes!";
            Console.WriteLine(customer);
            Console.WriteLine(copy);
        }
Пример #5
0
        static void Main(string[] args)
        {
            Customer customer1 = new Customer(
                "Ivana",
                "Dragancheva",
                "Koeva",
                "6603347878",
                "Sofia",
                "088123456",
                "*****@*****.**",
                CustomerType.Regular);

            customer1.AddPayment(new Payment("Slanina", 4.12M));

            Customer customer2 = new Customer(
                "Pesho",
                "Tichev",
                "Savov",
                "3412541200",
                "Plovdiv",
                "0884554475",
                "*****@*****.**",
                CustomerType.Diamond
                );

            customer2.AddPayment(new Payment("Books", 16.00M));

            Console.WriteLine(customer1 == customer2);

            var customer3 = (Customer) customer1.Clone();
            customer3.AddPayment(new Payment("House", 50000M));

            Console.WriteLine(customer1);
            Console.WriteLine(customer2);
            Console.WriteLine(customer3);

            var compare = customer3.CompareTo(customer1);
            Console.WriteLine(compare);
        }
        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()));
        }
Пример #7
0
 public object Clone()
 {
     Customer clone = new Customer(this.FName,this.MName,this.LName, this.EGN, this.Address, this.MName, this.Email,this.Type);
     this.Payments.ForEach(x => clone.AddPayment(x));
     return clone;
 }
Пример #8
0
 protected bool Equals(Customer other)
 {
     return string.Equals(FName, other.FName) &&
         string.Equals(MName, other.MName) &&
         string.Equals(LName, other.LName) &&
         this.EGN == other.EGN &&
         string.Equals(Address, other.Address) &&
         string.Equals(MPhone, other.MPhone) &&
         string.Equals(Email, other.Email) &&
         Type == other.Type;
 }