Hi,
I have just started learning lambda expressions.
Is it possible to simplify the following code down further:
Customer customer = Customers.FirstOrDefault(c => c.ID == 3);
if (customer == null)
{
customer = new Customer() { FirstName = "Ben", LastName = "Foster", ID = 3 };
Customers.Add(customer);
}
// do something with customer
customer.CreateProfile();
Essentially I want to check if an object exists in a collection. If it doesn't I want to create it, add it to the collection and use it later on.
Thanks Ben