I have method a the returns something like this:
List<Customer> customers = repository.GetCustomers.Where(x => x.IsActive);
return customers;
Visual Studio tooling is suggesting an inline temporary variable:
return repository.GetCustomers.Where(x => x.IsActive);
Years ago I heard a tip on a .Net podcast (the guest I don't recall) that there are some memory/performance advantages to the first option.
The micro-optimization question talks about this issue in a broad context. But is it indeed micro-optimization or style preference only?
customers
and to inline it means replacing its only use with the initialization expression. There's no such thing as an "inline temporary variable". – Sebastian Redl Mar 28 '20 at 11:12