Duplicate data C#

Asked

Viewed 97 times

0

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

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

When I have the list values displayed, the results are:

Name: Lucas Silva CPF: 222.333.4445-4

Name: Lucas Silva CPF: 222.333.4445-4

  • 1

    Welcome to Stackoverflow! Please, so we can help, post the code that populates the list and the code that iterates the list. Always post the code and preferably, do not use codes or results as an image, but as "pure" text. It is better for viewing.

  • You can put your code?

  • @Weslei, show us your code so we can help you, because we’ll have a way to identify the problem.

1 answer

2

Are you sure you are instantiating a new object with each 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"});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.