I\'d like to have a class \"A\" with a (for example) SortedList collection \"SrtdLst\" property, and inside this class \"A\" allow the addition or subtraction of \"SrtdLst\" ite
Just make the list private, and expose it as an indexer:
class A {
private SortedList _list;
public A() {
_list = new SortedList()
}
public string this[string key] {
get {
return _list[key];
}
set {
_list[key] = value;
}
}
}
Now you can only access the items using the index:
a["KeyA"] = "ValueBBB";
However, as the indexer of the list allows creation of new items, you would have to add code in the indexer to prevent that if you don't want that do be possible.