lblanes

Exemplo OO

Jan 11th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. namespace ConsoleApplication1
  2. {
  3.     class Pessoa
  4.     {
  5.         public string Nome { get; set; }
  6.         public Double Altura { get; set; }
  7.  
  8.         internal void Mostrar()
  9.         {
  10.             Console.WriteLine("Nome: " + this.Nome + " ... Altura: " + this.Altura.ToString("N2"));
  11.         }
  12.     }
  13.  
  14.     class Time
  15.     {
  16.         public Pessoa Pessoa1 { get; set; }
  17.         public Pessoa Pessoa2 { get; set; }
  18.         public Pessoa Pessoa3 { get; set; }
  19.  
  20.         public void Mostrar()
  21.         {
  22.             Console.WriteLine("..:: Dados dos membros do time ::..");
  23.             if (this.Pessoa1 != null) this.Pessoa1.Mostrar();
  24.             if (this.Pessoa2 != null) this.Pessoa2.Mostrar();
  25.             if (this.Pessoa3 != null) this.Pessoa3.Mostrar();
  26.         }
  27.     }
  28.  
  29.     class Program
  30.     {
  31.         static void Main(string[] args)
  32.         {
  33.             Time time = new Time();
  34.             time.Pessoa1 = new Pessoa();
  35.             time.Pessoa1.Nome = "Leandro";
  36.             time.Pessoa1.Altura = 1.74;
  37.  
  38.             time.Pessoa2 = new Pessoa();
  39.             time.Pessoa2.Nome = "Vinícios";
  40.             time.Pessoa2.Altura = 1.74;
  41.  
  42.             time.Mostrar();
  43.  
  44.             Console.ReadKey();
  45.         }
  46.     }
  47. }
Add Comment
Please, Sign In to add comment