I have the following class:
class SampleClass
{
private ArrayList mMyList;
SampleClass()
{
// Initialize mMyList
}
public ArrayList MyLis
You should wrap the return value in a read only collection.
Use the ArrayList.ReadOnly() method to construct and return a read-only wrapper around the list. it won't copy the list, but simply make a read-only wrapper around it. In order to get compile-time checking, you probably want to return the read-only wrapper as IEnumerable as @Jared suggests.
public IEnumerable MyList
{
get { return ArrayList.ReadOnly(mMyList); }
}
A collection that is read-only is simply a collection with a wrapper that prevents modifying the collection. If changes are made to the underlying collection, the read-only collection reflects those changes.
This method is an O(1) operation.
Reference