I am new to programming. I am having problem understanding the below code.
- What is the specific reason we are using IEnumerable here?
- return new List {} - is this an anonymous method?
- Why can't we use list as a return type rather than IEnumerable?
Sorry if this is a stupid question, but I would really appreciate if someone breaks down the below code.
private IEnumerable<Customer> GetCustomers()
{
return new List<Customer>
{
new Customer { Id = 1, Name = "John Smith" },
new Customer { Id = 2, Name = "Mary Williams" }
};