什么是类,函数,变量等在C#中正确的命名符号? [英] What is the correct naming notation for classes, functions, variables etc in c#?
问题描述
我跟在我身后没有正式计算后台的Web开发者,现在我已经好几年了编写代码,但每次我需要创建一个新的类/函数/变量,我花了大约两分钟就决定一个名字,然后如何输入。
I'm a web developer with no formal computing background behind me, I've been writing code now some years now, but every time I need to create a new class / function / variable, I spend about two minutes just deciding on a name and then how to type it.
举例来说,如果我写一个函数来总结了一串数字。我应该把它叫做
For instance, if I write a function to sum up a bunch of numbers. Should I call it
Sum()
GetSum()
getSum()
get_sum()
AddNumbersReturnTotal()
我知道有这样做的权利路,一个良好的权威来源的链接是我问:D
I know there is a right way to do this, and a link to a good definitive source is all I ask :D
作为封闭的 C#编码标准/最佳做法
Closed as a duplicate of c# Coding standard / Best practices
推荐答案
类应该在骆驼符号的第一个字母大写
Classes should be in camel notation with the first letter capitalized
public class MyClass
在C#函数和方法应该以类似的方式行事,除了私有方法
Functions and Methods in C# should act in a similar fashion except for private methods
public void MyMethod()
private void myPrivateMethod()
变量我倾向于做一些不同:
Variables I tend to do a little differently:
成员变量
private int _count;
局部变量
Local variables
int count;
这篇关于什么是类,函数,变量等在C#中正确的命名符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!