How to return an array - null or empty?
I was writing some code today and had a few methods that were returning arrays of values. I was wondering what the guidelines were about the proper way to return an array from an API so I did a quick search and turned up the following:
“String and Array properties should never return a null reference. Null can be difficult to understand in this context. The general rule is that null, empty string (”"), and empty (0 item) arrays should be treated the same way. Return an empty array instead of a null reference.” — from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconarrayusageguidelines.asp
This makes a lot of sense and takes the burden off the developer of having to check for null in the returned value before doing something as simple as checking its length.
