I have a class, let’s call it ‘ClassA’ with a private nested class, let’s call it ‘ClassB’. ‘ClassA’ contains a private instance of ‘ClassB’. Then inside ‘ClassA’ I have a list, so it looks something like this:
class ClassA
{
ClassB b = new ClassB();
List l;
class ClassB
{
}
}
My question is how would I give ‘ClassB’ the ability to modify 'ClassA’s private List so that ‘ClassB’ would be able to add and remove items from it? I have tried passing the List into the constructor of ‘ClassB’, since List is a class I figured it would pass by reference and any changes to the List in ‘ClassB’ would also change the list in ‘ClassA’, but that seems to create a new List.
I found the problem. At some point in ‘ClassA’ I clear the list by using ‘list = new List()’, which is what was creating a separate list. I changed it to use the Clear() function instead. Thanks for the help!