JRockFL
asked on
Is setting this variable making a duplicate in memory
Please see the code below. Is there a performance issue with setting this variable?
var results = GetAll();
Am i making a copy of this in memory?
var results = GetAll();
Am i making a copy of this in memory?
public class CustomerService
{
private readonly CustomerRepository repository;
public CustomerService(CustomerRepository repository)
{
this.repository = repository;
}
public IEnumerable<Customer> GetAll()
{
return repository.Get();
}
public IEnumerable<Customer> GetById(int id;)
{
var results = GetAll(); //any performance issues with this?
//rest of code omittted
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why retrieve all records from the repository when you know which single record you want?
ASKER
Fernando Soto
That is not my concern right now. All of the records are stored in memory.
That is not my concern right now. All of the records are stored in memory.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.