I have a list like this:
List list = new List
How to handle adding new position to this list?
When
To piggy-back off Ahmad's use of Extension Methods, you can create your own class where the list is private with a public get
method and a public add
method.
public class MyList
{
private List PrivateSomeClassList;
public List SomeClassList
{
get
{
return PrivateSomeClassList;
}
}
public void Add(SomeClass obj)
{
// do whatever you want
PrivateSomeClassList.Add(obj);
}
}
However, this class only provides access to List<>
methods that you manually expose...hence may not be useful in cases where you need a lot of that functionality.