Use existing or create new

suggest change

A 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 };

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents