Another good idea is to return the list as enumerable using:
return m_privateCollection.AsEnumerable();
Now what are the differences?
AsReadOnly()
creates a completely new collection of list. Depending on the count of items and where the resource is, this may take a long time.AsEnumerable()
returns exactly the items stored on the list, but one by one (probably using yield
). Therefore adding and removing the items are not meaningful actions.AsEnumerable()
is lazy load. It means that AsEnumerable()
won't query the items until the time you want to encounter the items. But methods like AsList()
and AsReadOnly()
create the list exactly at the time you call them.