DEV Community

Discussion on: No more NullReferenceException for Lists in C#

Collapse
 
webbes profile image
webbes

It is never a good idea to hide programming errors and that is what you are doing in effect. This can and will become a root cause for a very nasty bug that is so difficult to track. If you one day pass the wrong (null) variable, your code pretends that there's no issue at all and continues. It's a bit like "on error resume next" or an empty catch block. Sure an empty catch block will prevent you from ever seeing an error again, so... it "works", but you will also never be sure that your code still functions correctly. If you've got null reference exceptions you are obviously not checking input parameters which you should. If you are an experienced developer, you will notice an uninstantiated variable in the same function in a glance. Trust me. It's like a portrait without a nose.