DEV Community

Discussion on: No more NullReferenceException for Lists in C#

Collapse
 
itr13 profile image
Mikael Klages • Edited

Having a second argument for out, and making sure that argument is always passed back to wherever you got the list from sounds like more work and more prone to error than just getting an NRE.

Some minor improvements:

list = list ?? new List<T>();
list.Add(value); //It can't be null, so ?. isn't needed