Clone() public method

public Clone ( ) : object
return object
コード例 #1
0
        static void Main(string[] args)
        {
            AnimalPrototype Sheep = new Sheep("Dolly");
            Sheep           Dolly = Sheep.Clone() as Sheep;

            Dolly.MakeSound();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var original = new Sheep("Jolly", "Mountain Sheep");

            Console.WriteLine(original.Name);     // Jolly
            Console.WriteLine(original.Category); // Mountain Sheep

            var cloned = original.Clone();

            cloned.Name = "Dolly";
            Console.WriteLine(cloned.Name);     // Dolly
            Console.WriteLine(cloned.Category); // Mountain Sheep
            Console.WriteLine(original.Name);   // Dolly

            Console.ReadLine();
        }