I have some code where I\'m returning an array of objects.
Here\'s a simplified example:
string[] GetTheStuff() {
List s = null;
This is not a direct answer to your question.
Read why arrays are considered somewhat harmful. I would suggest you to return an IList
IList GetTheStuff() {
List s = new List();
if( somePredicate() ) {
// imagine we load some data or something
}
return s;
}
In this way the caller doesn't have to care about empty return values.
EDIT: If the returned list should not be editable you can wrap the List inside a ReadOnlyCollection. Simply change the last line to. I also would consider this best practice.
return new ReadOnlyCollection(s);