public bool Equals(UserRef 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); }
private static void TestUserRef() { Console.Clear(); Console.WriteLine("****************************REFERENCE_TYPE****************************"); var user1 = new UserRef(); var user2 = new UserRef("Ivan", "Ivanov", (decimal)500.00, "*****@*****.**", DateTime.Today); var user3 = UserRef.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 changes in another - reference type user1.ChangeSalary(); Console.WriteLine($"\nI've just changed value of user1"); Console.WriteLine("user1:"); user1.PrintUser(); Console.WriteLine("user4:"); user4.PrintUser(); Console.ReadKey(); }
public static UserRef Clone(UserRef obj) { var tempUser = new UserRef(obj._name, obj._surname, obj._salary, obj._email, obj._applymentsDate); return(tempUser); }