Why to define
IEnumerable Locations
and not just makeLinkedList m_list
to be public property?
Several possible reasons:
What if later you decide you don't want to implement it as a
LinkedList<>
but as a regularList
? Or a lazy-loaded collection type? or an array?Exposing the collection as a generic
IEnumerable<T>
allows you to change out the internal implementation later without changing the public contract.If you make the collection a property (with
get; set;
accessors) you are allowing clients to add to, remove from, even replace the entire list. Exposing it asIEnumerable
indicates that the list is intended to be read-only (unless you exposeAdd
methods somewhere else).
I don't know how do I use Locations property from Kuku.
Sure you do - you're already doing it in your sample:
foreach (MyClass c in input.Locations)
{
}
Or you can use Linq to search for or aggregate data from the collection (foreach
is still appropriate for updating the instances.