fork download
  1. using static System.Console;
  2. using System.Collections.Generic;
  3.  
  4. namespace ListaObjeto {
  5. public class Pessoa {
  6. public Pessoa() {
  7. Nome = "";
  8. Idade = 0;
  9. }
  10.  
  11. public Pessoa(string nome, int idade) {
  12. Nome = nome;
  13. Idade = idade;
  14. }
  15.  
  16. public string Nome { get; set; }
  17. public int Idade { get; set; }
  18. }
  19.  
  20. public class Program {
  21. public static void Main(string[] args) {
  22. var listaPessoa = new List<Pessoa>();
  23. listaPessoa.Add(new Pessoa("João", 18));
  24. listaPessoa.Add(new Pessoa());
  25. foreach (var pessoa in listaPessoa) WriteLine($"Nome: {pessoa.Nome} - Idade {pessoa.Idade}");
  26. }
  27. }
  28. }
  29.  
  30. //https://pt.stackoverflow.com/q/99562/101
Success #stdin #stdout 0.02s 16256KB
stdin
Standard input is empty
stdout
Nome: João - Idade 18
Nome:  - Idade 0