In Class A(What will output the List if it is not empty):
private List<int> _myList = new List<int>
public List<int> MyList {get{return _myList;} set{_myList = value;}}
In Class B:
public bool MyClassBMethod(stuff)
{
//stuff
try{
something
}
catch(Exception){
ClassA.MyList.Add(stuff);
return false;
}
return true;
}
Is editing a List like this bad practice? Or is it okay?
Edit: I am only adding to the list as such when my method needs to return something else(bool, object, string, etc).
In general, a class should be responsible for managing its own internal state. By giving full public access to a member like this, you are basically saying that Class A is giving up responsibility of that part of its state. It cannot make assumptions about what _myList contains because anyone could change that at any time.
Whether that’s good or not depends on what your intent is, but it certainly runs contrary to the ideas of decoupling and encapsulation. Again, whether you want decoupling and encapsulation is up to you.
A better question would be to determine what sort of decoupling between classes A and B would be most beneficial to your design, and then you’d be able to decide what member to expose and how.