I am attempting to reduce the lines in my code as a means to improve the execution speed of my windows application. So far, I've come to understand the usefulness of using properties when it comes to adding conditions within the get and set fields. I am not certain though if relying on properties helps improve the time complexity in comparison to setting a basic value followed by conditional statements in certain methods. I will provide an example on what I did first and what I improved. If anyone can share some advice on if the current improvement helps reduce processing time as well as if it follows the simplest Big-O Notation that is hopefully O(n), I'd appreciate the feedback.
Old
public float tempP1 = 1.0f;
public void addToP1() {
tempP1 += 0.4f;
tempP1 = (tempP1 > 2.0f) ? 2.0f : tempP1;
}
New
private float _tempP1 = 1.0f;
public float tempP1 { get { return this._tempP1; }
set {
value = (value > 2.0f) ? 2.0f : value;
this._tempP1 = value;
}
}
public void addToP1() {
tempP1 += 0.4f;
}