.NET v2
When the List has a very useful (4 me) method AsReadOnly() the LinkedList does not have such a method.
Is there a way to "quickly" interface an internal LinkedList to read only from the external code?
Why not just return a IEnumerable<T>
? If you just want to let users enumerate the list without modifying it*, IEnumerable is the obvious choice.
If you want to have a read only interface of the LinkedList interface, you can wrap LinkedList, forward read only methods to the wrapped list and deny any changes.
*) Keep in mind that neither ReadOnlyCollection not IEnumerable will prevent callers to change state of objects in case of a collection of reference types. If the objects should be read only as well, you need to implement this as part of their type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With