fork download
  1. using static System.Console;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace LinqConsulta {
  6. public class Program {
  7. public static void Main() {
  8. foreach (var item in new Empregados().Lista().OrderBy(e => e.Nome).ToList()) WriteLine(item.Nome);
  9. }
  10. }
  11.  
  12. class Empregados : List<Empregado> { //não é recomendável fazer isto
  13. public Empregados Lista() {
  14. this.Add(new Empregado(1, "Maria", "maria@site.com.br", "11 1111 1111"));
  15. this.Add(new Empregado(2, "João", "joao@site.com.br", "22 2222 2222"));
  16. this.Add(new Empregado(3, "José", "jose@site.com.br", "33 3333 3333"));
  17. return this;
  18. }
  19. }
  20. class Empregado {
  21. public int Id { get; set; }
  22. public string Nome { get; set; }
  23. public string Email { get; set; }
  24. public string Telefone { get; set; }
  25. //tirei o construtor vazio que só permitia criar um obejto inválido
  26. public Empregado(int id, string nome, string email, string telefone) {
  27. Id = id;
  28. Nome = nome;
  29. Email = email;
  30. Telefone = telefone;
  31. }
  32. }
  33. }
  34.  
  35. //https://pt.stackoverflow.com/q/133780/101
Success #stdin #stdout 0.03s 18092KB
stdin
Standard input is empty
stdout
João
José
Maria