Ejemplo n.º 1
0
        public bool Equals(UserStruct obj)
        {
            if (this._name != obj._name)
            {
                return(false);
            }

            if (this._surname != obj._surname)
            {
                return(false);
            }

            if (this._salary != obj._salary)
            {
                return(false);
            }

            if (this._email != obj._email)
            {
                return(false);
            }

            if (this._applymentsDate != obj._applymentsDate)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private static void TestUserStruct()
        {
            Console.Clear();
            Console.WriteLine("****************************STRUCT_TYPE****************************");

            var user1 = new UserStruct("Vladyslav", "Chernytsyn", (decimal)1000.00, "*****@*****.**", DateTime.Today);
            var user2 = new UserStruct("Ivan", "Ivanov", (decimal)500.00, "*****@*****.**", DateTime.Today);
            var user3 = UserStruct.Clone(user1);
            var user4 = user1;

            user1.PrintUser();
            user2.PrintUser();
            user3.PrintUser();
            user4.PrintUser();

            Console.WriteLine($"user1 is equal user2 ? answer :{user1.Equals(user2)}");
            Console.WriteLine($"user1 is equal user3 ? answer :{user1.Equals(user3)}");


            Console.WriteLine($"\nComparison of the objects created by clone method \n" +
                              $"user1 is referencing data of user3? {Object.ReferenceEquals(user1, user3)}");
            Console.WriteLine($"\nComparison of the objects created by operator = \n" +
                              $"user1 is referencing data of user4? {Object.ReferenceEquals(user1, user4)} \n");

            // changing data in one user - so it doesn't changes in another - value type
            user1.ChangeSalary();

            Console.WriteLine($"\nI've just changed value of user1");

            Console.WriteLine("user1:");
            user1.PrintUser();

            Console.WriteLine("user4:");
            user4.PrintUser();

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public static UserStruct Clone(UserStruct obj)
        {
            var tempUser = new UserStruct(obj._name, obj._surname, obj._salary, obj._email, obj._applymentsDate);

            return(tempUser);
        }