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; }
Interface names should be capitalized like class names. Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter.
Use camel casing ("camelCasing") when naming private or internal fields, and prefix them with _ . When editing C# code that follows these naming conventions in an IDE that supports statement completion, typing _ will show all of the object-scoped members.
We have to start a variable name with a double underscore to represent it as a private variable (not really). Example:- one, two, etc..,. As we already said the variables whose names start with a double underscore are not private.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With