コード例 #1
0
        static void Exercicio2()
        {
            Porta porta = new Porta(2.10, 1.0);

            Console.WriteLine(porta.Aberta);
            porta.Abrir();
            Porta clonePorta = (Porta)porta.Clone();

            Console.WriteLine(porta.Aberta);
            clonePorta.AlterarAltura(3.20);
            Console.WriteLine(clonePorta.Altura);
            Console.WriteLine(porta.Altura);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: radamantes/softblue
        static void Main(string[] args)
        {
            //CRIO PORTA 1
            Porta p1 = new Porta(1.95, 0.90);

            p1.Abrir(); //lembrando que a referenci ao objeto é a mesma então se altera em um objeto altera no outro;

            Console.WriteLine(" P1 " + " -> Altura = " + p1.Altura);
            Console.WriteLine(" P1 " + " -> Altura = " + p1.Largura);
            Console.WriteLine(" P1 " + " -> Altura = " + p1.Aberta);



            //CRIO O CLONE DA PORTA 1
            Porta p2 = (Porta)p1.Clone(); //define para p2 o clone do objeto p1 a mesma referencia // FIZ O CASTINGO POIS RETORNA UM OBJETO ENTÃO TEMOS QUE DIZER QUAL É O TIPO DO OBJETO NO CASO PORTA

            Console.WriteLine(" P2 " + " -> Altura  = " + p2.Altura);
            Console.WriteLine(" P2 " + " -> Altura  = " + p2.Largura);
            Console.WriteLine(" P2 " + " -> Altura  = " + p2.Aberta);
        }