对于我在这里称为"_Add“的私有方法,是否有命名约定?我不喜欢前面的下划线,但这是我的一个队友建议的。
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;
}发布于 2008-12-20 23:22:55
我通常看到并使用"AddCore“或"InnerAdd”
发布于 2008-12-20 23:04:33
我从来没有在C#中看到过区分公有方法和私有方法的编码约定。我不建议这样做,因为我看不到好处。
如果方法名与公共方法冲突,则是时候变得更具描述性了;如果像您的示例一样,它包含公共方法的实际方法实现,一种惯例是将其称为*Impl。也就是说,在你的情况下是AddImpl。
发布于 2008-12-20 23:16:43
我通常对私有方法使用thisCase,对公共方法使用ThatCase。
private Vector add(Vector vector) {
for (int index = 0; index < Length; index++) {
this[index] += vector[index];
}
return this;
}
public Vector Add(Vector vector) {
for (int index = 0; index < Length; index++) {
this[index] += vector[index];
}
return this;
}https://stackoverflow.com/questions/383850
复制相似问题