Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- List<Aluno> aluno = new List<Aluno>{
- new Aluno() { AlunoId = 1, Nome = "Cláudia",Email="claudia@email.com" },
- new Aluno() { AlunoId = 2, Nome = "Pedro",Email="pedro@email.com" },
- new Aluno() { AlunoId = 3, Nome = "Eduardo",Email="eduardo@email.com" }
- };
- Console.WriteLine("==================================");
- foreach (var item in aluno)
- {
- Console.WriteLine("ID: {0}nNome: {1}nEmail: {2}", item.AlunoId, item.Nome,item.Email);
- Console.WriteLine("==================================");
- }
- Console.WriteLine("nLista Atualizadan");
- int iElemento = 1;
- var elem = aluno.Where<Aluno>(a => a.AlunoId == iElemento).FirstOrDefault();
- int index = aluno.IndexOf(elem);
- aluno[index].Nome = "Cláudia Limeira";
- aluno[index].Email = "claudia_limeira@email.com";
- foreach (var item in aluno)
- {
- Console.WriteLine("ID: {0}nNome: {1}nEmail: {2}", item.AlunoId, item.Nome, item.Email);
- Console.WriteLine("==================================");
- }
- Console.Read();
- }
- }
- class Aluno
- {
- public int AlunoId { get; set; }
- public string Nome { get; set; }
- public string Email { get; set; }
- }
- var item = aluno.First(x => x.Id == 1); //Localizando o aluno com id 1
- item.Nome = "Novo nome";
- item.Email = "aluno@aluno.com";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement