DEV Community

Discussion on: No more NullReferenceException for Lists in C#

Collapse
 
jhbertra profile image
Jamie Bertram

Pro tip: until nullable reference types hit primetime, use JetBrains.Annotations and add NotNull / CanBeNull attributes to all reference-type fields, properties, parameters and return types. As long as you run ReSharper and fix all warnings, you should never have a NullReferenceException again.

Even better - install ReCommended extensions for ReSharper, and make it a warning to not annotate reference types. Your code should now be almost NullReferenceException-proof.

Enjoy never worrying about this error again.