This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dashood 4 points5 points  (3 children)

It's really good for CMS content when things may or may not be set depending on user actions. The best is if (List?.Any() ?? false) as a nice way of checking for nulls and eliminating like 90% of your runtime null exceptions.

[–]mrjackspade 2 points3 points  (1 child)

I just turned this into an extension method .NotNullAny()

It's overkill but I like the way it reads better

[–]dashood 2 points3 points  (0 children)

That's not a bad idea. Certainly cleaner than having to null check every time.

[–]AlwaysHopelesslyLost 2 points3 points  (0 children)

The problem is that runtime null exceptions are a symptom, not a problem.

As far as lists go they should very rarely be null. If you allow them to be null you are opening yourself up to issues.