Ejemplo n.º 1
0
        public static void CallShallowCopy()
        {
            Console.WriteLine("Shallow Copy Example");

            var author = new AuthorShallowCopy()
            {
                Name           = "Stephan Walther",
                TwitterAccount = "http://www.twitter.com/swalther",
                Website        = "http://www.superexpert.com",
                HomeAddress    = new Shallow.Address
                {
                    City  = "New York",
                    State = "Nevada"
                }
            };

            Console.WriteLine("\n Originial Copy");
            PrintShallowDetails(author);

            AuthorShallowCopy clonedObject = (AuthorShallowCopy)author.Clone();

            Console.WriteLine("\n Cloned Copy");
            PrintShallowDetails(clonedObject);

            Console.WriteLine("\n Make Changes to clone copy address");

            clonedObject.Name              = "Changed Name";
            clonedObject.TwitterAccount    = "http://www.twitter.com/changedaccount";
            clonedObject.Website           = "http://www.microsoft.com";
            clonedObject.HomeAddress.City  = "Los Angles";
            clonedObject.HomeAddress.State = "North Carolina";

            Console.WriteLine("\n Cloned object After Update");
            PrintShallowDetails(clonedObject);

            Console.WriteLine("\n Original Copy");
            PrintShallowDetails(author);
        }
Ejemplo n.º 2
0
 private static void PrintShallowDetails(AuthorShallowCopy author)
 {
     Console.WriteLine("\n\t" + author.Name + "\n\t" + author.TwitterAccount + "\n\t" + author.Website);
     Console.WriteLine("\t" + author.HomeAddress.City + "\n\t" + author.HomeAddress.State);
 }