I do not understand the following: In the code below, Visual Studio tells me that I can simplify my code by deleting the second keyword thisin the constructor.
But why can not I give up the first keyword this? Both variables were declared outside the constructor in the class, so both instances will be "overridden" * for the instance.
If I delete both words this, then VS will complain that the first assignment is for the same variable, but not for the second. The only obvious difference for me is the second variable is an array, but I don't understand how this could change?
* I suspect that redefinition here is not correct.
public class CelestialObject {
CelestialBody[] celestialBodies;
int celestialBodyCount;
public CelestialObject(int celestialBodyCount = 2) {
this.celestialBodyCount = celestialBodyCount;
this.celestialBodies = new CelestialBody[celestialBodyCount];
}
}