示例#1
0
        static void Main()
        {
            var mother    = new PersonCloneable("Mom", 49);
            var father    = new PersonCloneable("Dad", 50);
            var origin    = new PersonCloneable("Son", 29, mother, father);
            var clone     = origin.Clone();
            var deepClone = origin.DeepClone();

            origin.Parent1.Name = "NewName";
            Console.WriteLine(
                $"origin.Parent1: {origin.Parent1}, " +
                $"clone.Parent1: {clone.Parent1}, " +
                $"deepClone.Parent1: {deepClone.Parent1}");
        }
示例#2
0
        /// <summary>
        /// Entry point.
        /// </summary>
        static void Main()
        {
            //Create objects to clone
            var mother = new PersonCloneable("Mom", 49);
            var father = new PersonCloneable("Dad", 50);
            var origin = new PersonCloneable("Son", 29, mother, father);

            // Make shallow copy
            var clone = origin.Clone();

            // Make deep copy
            var deepClone = origin.DeepClone();

            // Change field value in origin
            origin.Parent1.Name = "NewName";
            Console.WriteLine(
                $"origin.Parent1: {origin.Parent1}, " +
                $"clone.Parent1: {clone.Parent1}, " +
                $"deepClone.Parent1: {deepClone.Parent1}");
        }