Question: Suppose I have a method that returns an array or list or some other collection. If something goes wrong inside or when there is simply no data to return, what is better - to return null or to return array (list, etc.) that has length (count) equal to 0?

In fact is it important, or it is just a matter of developer's preferences?

Answer: 
If something goes wrong then you shouldn't be returning anything, rather throwing an exception.

**You need to agree a consistent approach for the project as to the meaning of NULL and {} and stick to it.** Either you are going to use NULL or not, if you are everyone needs to know to check.

I like to think of NULL - not tried to or see if there is anything, there might be some but who knows.

Empty collection - tried to populate and as far as the system is concerned there are no items, which is quite a strong statement.

e.g. Wallet.Notes collection.

* NULL - I haven't opened my wallet, so I don't know if I have any notes in it.
* List={} - I've checked and I definitely don't have any notes cos I spent it all on beer.
Although I'd say it's mostly a matter of developer's preference, to return an empty collection might be a better approach.

Let's say you have an object which contains a collection member.

```
public class Customer {
    private IList<Order> _orders;

    public Customer() {
        _orders = new List<Order>();
    }

    public IList<Order> Orders {
        get {
            return _orders;
        } 
    }
}

```

One generally will prefer to have this member as a readonly property so that its customer's orders don't get lost without any apparent reason. So, returning `null` is not an option. You would likely work better with an empty collection than a null reference. As such, instantiating the collection within the class constructor is a better approach.

And most importantly, when using DataBinding, for instance, you might get strange behaviour when returning null collection reference, as it will best work with an empty collection instead.

Another example, when iterating through a collection such as:

```
foreach (Order o in c.Orders) {
    // Do something here...
}

```

This `foreach` loop will simply not get executed when the collection is empty, without you having to check whether it is a null reference first. It simplifies the code and minimizes its complexity.

This depends on the scenario you're wokring in.