fork download
  1. using static System.Console;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program {
  6. public static void Main(string[] args) {
  7. var alunos = new List<Aluno> {
  8. new Aluno() { AlunoId = 1, Nome = "Cláudia", Email = "claudia@email.com" },
  9. new Aluno() { AlunoId = 2, Nome = "Pedro", Email = "pedro@email.com" },
  10. new Aluno() { AlunoId = 3, Nome = "Eduardo", Email = "eduardo@email.com" }
  11. };
  12. ImprimeAlunos(alunos);
  13. while (true) {
  14. var id = 0;
  15. Write("Qual ID de aluno deseja modificar? (-1 para encerrar)");
  16. if (int.TryParse(ReadLine(), out id)) {
  17. if (id == -1) break;
  18. var alunoAchado = alunos.FirstOrDefault(x => x.AlunoId == id);
  19. if (alunoAchado != null) {
  20. Write("Qual o novo nome? ");
  21. alunoAchado.Nome = ReadLine();
  22. Write("Qual o novo e-mail? ");
  23. alunoAchado.Email = ReadLine();
  24. } else WriteLine("Id inválido tente outro");
  25. } else WriteLine("Id inválido tente outro");
  26. }
  27. WriteLine("Nova Lista");
  28. ImprimeAlunos(alunos);
  29. }
  30.  
  31. static void ImprimeAlunos(List<Aluno> alunos) {
  32. WriteLine("==================================");
  33. foreach (var item in alunos) {
  34. WriteLine($"ID: {item.AlunoId}\nNome: {item.Nome}\nEmail: {item.Email}");
  35. WriteLine("==================================");
  36. }
  37. }
  38. }
  39.  
  40. class Aluno {
  41. public int AlunoId { get; set; }
  42. public string Nome { get; set; }
  43. public string Email { get; set; }
  44. }
  45.  
  46. //https://pt.stackoverflow.com/q/87315/101
Success #stdin #stdout 0.02s 17268KB
stdin
1
abc
abc@abc@abc.com
-1
stdout
==================================
ID: 1
Nome: Cláudia
Email: claudia@email.com
==================================
ID: 2
Nome: Pedro
Email: pedro@email.com
==================================
ID: 3
Nome: Eduardo
Email: eduardo@email.com
==================================
Qual ID de aluno deseja modificar? (-1 para encerrar)Qual o novo nome? Qual o novo e-mail? Qual ID de aluno deseja modificar? (-1 para encerrar)Nova Lista
==================================
ID: 1
Nome: abc
Email: abc@abc@abc.com
==================================
ID: 2
Nome: Pedro
Email: pedro@email.com
==================================
ID: 3
Nome: Eduardo
Email: eduardo@email.com
==================================