If you have a method that queries the DB and returns a collection populated with the records found, what should be returned upon no records found?
-
A new collection with
.Count== 0 -
null
Is there any consensus on this?
Or returning null and returning an empty collection should have different meanings?
You should return an empty collection. That will avoid you to check every time that you got a null as return.
You will always have a code like (abstract code):
instead of:
Additionally, you could extend this to the NULL Object pattern if you need more complex behavior from your collection.