Use existing or create new
suggest changeA common usage scenario that this feature really helps with is when you are looking for an object in a collection and need to create a new one if it does not already exist.
IEnumerable<MyClass> myList = GetMyList();
var item = myList.SingleOrDefault(x => x.Id == 2) ?? new MyClass { Id = 2 };
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents