I have the following class:
class SampleClass
{
private ArrayList mMyList;
SampleClass()
{
// Initialize mMyList
}
public ArrayList MyLis
Just make the property as Sealed (or NotInheritable in VB.NET) and readonly, like this:
public sealed readonly ArrayList MyList
{
get { return mMyList;}
}
Also don't forget to make the backing field as readonly:
private readonly ArrayList mMyList;
But in order to initialize the value of mMyList, you must initialize it ONLY in the constructor, as in this example:
public SampleClass()
{
// Initialize mMyList
mMyList = new ArrayList();
}