/// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="other"></param>
        public PersonLuckyNumbers(PersonLuckyNumbers other)
            : base(other)
        {
            Console.WriteLine("PersonLuckyNumbers->PersonLuckyNumbers(PersonLuckyNumbers other)");

            LuckyNumbers = new int[other.LuckyNumbers.Length];
            for (var i = 0; i < other.LuckyNumbers.Length; i++)
            {
                LuckyNumbers[i] = other.LuckyNumbers[i];
            }
        }
Esempio n. 2
0
        private static void ShallowCopyEqualOperator()
        {
            //Operator= - Shallow copy
            var p1 = new PersonLuckyNumbers("Name 1", 21, new [] { 13, 26, 39 });
            var p2 = p1;

            p1.Age             = 12;
            p1.LuckyNumbers[0] = 1;

            Console.WriteLine(p1);
            Console.WriteLine(p2);
        }
Esempio n. 3
0
        private static void DeepCopyCopyConstructor()
        {
            var p1 = new PersonLuckyNumbers("Name 1", 21, new[] { 13, 26, 39 });

            Console.WriteLine();
            var p2 = new PersonLuckyNumbers(p1);

            p1.Age             = 12;
            p1.LuckyNumbers[0] = 1;

            Console.WriteLine(p1);
            Console.WriteLine(p2);
        }
        private static void DeepCopyICloneable()
        {
            var p1 = new PersonLuckyNumbers("Name 1", 21, new[] { 13, 26, 39 });

            Console.WriteLine();

            //Cast to base type
            var p2 = p1.Clone();

            p1.Age             = 12;
            p1.LuckyNumbers[0] = 1;

            Console.WriteLine(p1);
            Console.WriteLine(p2);
        }