Is there a convention for naming the private method that I have called "_Add
" here? I am not a fan of the leading underscore but it is what one of my teammates suggests.
public Vector Add(Vector vector) {
// check vector for null, and compare Length to vector.Length
return _Add(vector);
}
public static Vector Add(Vector vector1, Vector vector2) {
// check parameters for null, and compare Lengths
Vector returnVector = vector1.Clone()
return returnVector._Add(vector2);
}
private Vector _Add(Vector vector) {
for (int index = 0; index < Length; index++) {
this[index] += vector[index];
}
return this;
}
I've never seen any coding convention in C# that distinguished between public and private methods. I don't suggest doing it, since I don't see the benefit.
If the method name conflicts with public methods, it’s time to become more descriptive; if, as in your case, it contains the actual method implementation for the public method, one convention is to call it *Impl
. I.e. AddImpl
in your case.