Advertisement
Guest User

Untitled

a guest
Sep 16th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. List<Aluno> aluno = new List<Aluno>{
  6. new Aluno() { AlunoId = 1, Nome = "Cláudia",Email="claudia@email.com" },
  7. new Aluno() { AlunoId = 2, Nome = "Pedro",Email="pedro@email.com" },
  8. new Aluno() { AlunoId = 3, Nome = "Eduardo",Email="eduardo@email.com" }
  9. };
  10.  
  11. Console.WriteLine("==================================");
  12.  
  13. foreach (var item in aluno)
  14. {
  15. Console.WriteLine("ID: {0}nNome: {1}nEmail: {2}", item.AlunoId, item.Nome,item.Email);
  16. Console.WriteLine("==================================");
  17. }
  18.  
  19. Console.WriteLine("nLista Atualizadan");
  20.  
  21. int iElemento = 1;
  22.  
  23. var elem = aluno.Where<Aluno>(a => a.AlunoId == iElemento).FirstOrDefault();
  24. int index = aluno.IndexOf(elem);
  25.  
  26. aluno[index].Nome = "Cláudia Limeira";
  27. aluno[index].Email = "claudia_limeira@email.com";
  28.  
  29. foreach (var item in aluno)
  30. {
  31. Console.WriteLine("ID: {0}nNome: {1}nEmail: {2}", item.AlunoId, item.Nome, item.Email);
  32. Console.WriteLine("==================================");
  33. }
  34.  
  35. Console.Read();
  36. }
  37. }
  38.  
  39. class Aluno
  40. {
  41. public int AlunoId { get; set; }
  42. public string Nome { get; set; }
  43. public string Email { get; set; }
  44. }
  45.  
  46. var item = aluno.First(x => x.Id == 1); //Localizando o aluno com id 1
  47.  
  48. item.Nome = "Novo nome";
  49. item.Email = "aluno@aluno.com";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement