Is having a List in an interface increasing overhead

Hello everyone,

Sorry if I’m not understanding this problem correctly, but I’m new to C#. So I have two interface class called IArmy and IUnit. In IArmy is a List of IUnit classes with a get keyword. (So an army contains a list of units)

In the implementation of IArmy, I have a List of Unit classes

public class Army : MonoBehaviour, IArmy
{
	List<IUnit> mUnitList;
	public List<IUnit> UnitList
	{
		get
		{
			return mUnitList;
		}
	}
	// Rest of the code
}

What I’m confused about is that I have UnitList and mUnitList. Is UnitList acting like a pointer to mUnitList, or do I have two lists thus creating extra memory by accident? I’m used to C++ pointers so I’m not 100% if what I’m doing is correct.

Thank you very much!

What you are using here is typically called an Accessor, or Property, and no it does not mean you have two lists.
Nor is it acting like a pointer, the get property (and the set property) act more like functions just like writting.

public List<IUnit> GetUnitList()
{
     return mUnitList;
}

Propertys allow you to do various things like validating values that are being set to the variable, abstract out the selection of a value to return from a pool of possible options, etc.

You don’t have to worry about extra memory overheads here. Just the processing overhead of any logic you put inside your get and set properties. which in this case is negligible as its just a return.