I know generally empty List is more prefer than NULL. But I am going to return NULL, for mainly two reasons
- I have to check and handle null values explicitly, avoiding bugs and attacks.
- It is easy to perform
??operation afterwards to get a return value.
For strings, we have IsNullOrEmpty. Is there anything from C# itself doing the same thing for List or IEnumerable?
nothing baked into the framework, but it’s a pretty straight forward extension method.
See here
Daniel Vaughan takes the extra step of casting to ICollection (where possible) for performance reasons. Something I would not have thought to do.