Reputation: 1397
If a method is inside a linq query would it be called multiple times? I can't test this because I don't have an IDE. I am learning linq and I use online c# compiler to run the program.
var List<Customer> CustomerList = (From c in GetCustomerList()
Where c.Id > 1
Select c).ToList()
Would this above code cause performance bottle necks since GetCustomerList method is inside the linq statement?
Upvotes: 2
Views: 290
Reputation: 15435
That's a decent concern, but you're fine here.
LINQ query syntax is translated to method calls. In your case,
var List<Customer> CustomerList = GetCustomerList()
.Where(c => c.Id > 1)
.ToList();
If you have doubts about it, add a call to Console.WriteLine
inside GetCustomerList()
, or take a look over the source for LINQ.
Upvotes: 1