Difficult to replicate objects (object Customer) on the list? [migrated]
- by gandolf
I wrote a program that does work with files like delete and update, store, and search And all customers But I have a problem with the method is LoadAll Once the data are read from the file and then Deserialize the object becomes But when I want to save the list of objects in the list are repeated. How can I prevent the duplication in this code?
var customerStr = File.ReadAllLines (address);
The code is written in CustomerDataAccess class DataAccess Layer.
Project File
The main problem with the method LoadAll Code:
public ICollection<Customer> LoadAll()
{
var alldata = File.ReadAllLines(address);
List<Customer> lst = new List<Customer>();
foreach (var s in alldata)
{
var objCustomer = customerSerializer.Deserialize(s);
lst.Add(objCustomer);
}
return lst;
}