Duplicate data C #

0

I made a basic C # registration system. I created a List<T> to keep my data in memory and then display them.

But when I register the second person, this data "clones" the other data.

When I display the list values, the results are:

  

Name: Lucas Silva Tax ID: 222.333.4445-4

     

Name: Lucas Silva Tax ID: 222.333.4445-4

    
asked by anonymous 17.03.2017 / 16:56

1 answer

2

Are you sure you are instantiating a new object with every insertion in the list?

List<MinhaClasse> MinhaLista = new List<MinhaClasse>();

MinhaLista.Add(new MinhaClasse{Nome="Lucas Silva", CPF ="222.333.444-4"});
MinhaLista.Add(new MinhaClasse{Nome="Maria Santos", CPF="444.555.666-7"});
    
17.03.2017 / 17:17