Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The preferred option to return would depend on the context of your application.

If you want to allow other developers to modify the items in the list, then you should return a List. In contrast, if you want to prevent modification of the list, you should return an IList or IEnumerable.

An IList is an interface that defines a read-write collection of elements, and it is preferred when you want to keep the collection ordered, or you need to insert or remove elements. On the other hand, IEnumerable is an interface that provides a read-only access to a collection of elements that can be enumerated.

List is a concrete implementation of the IList interface while List<class> is a generic List that takes a type parameter. The main difference between the two is that List<class> is strongly typed, meaning that it can only hold objects of the specified class type, while List can hold any type of object.

Overall, the choice between these options will depend on the specific requirements of your application, and you should choose the one that best fits your needs.