I was browsing some documentation for a physics library for XNA and noticed an example someone had used for creating a class for a Car.
This is a pretty simple example:
Class Car
{
private float gravity;
private float maxSpeed;
public Car(float gravity, float maxSpeed)
{
this.gravity = gravity;
this.maxSpeed = maxSpeed;
}
}
Now when i've created a constructor and set up the assigning of the passed in parameters I would do it this way:
Class Car
{
private float _gravity;
private float _maxSpeed;
public Car(float gravity, float maxSpeed)
{
_gravity = gravity;
_maxSpeed = maxSpeed;
}
}
Is there any advantage to either approach? I've only come across this a few times but I assume there's a good reason for doing so, I'm just looking for the "best practice" way so to speak.
Thanks!