What is the universally accepted naming convention for c#? (functions, classes, parameters, local variables, namespaces, etc)
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Microsoft has an excellent set of guidelines on class library design, including a section on naming. In short (examples in parentheses):
WebRequest
)IDisposable
)ToUpper
)Length
)Click
)System.Collections
; unusual to have two words in one part though)keySelector
)Int32.MaxValue
)HttpStatusCode
,BindingFlags
)ThreadStaticAttribute
)Private names are up to you, but I tend to follow the same conventions as for everything else. Hungarian notation (in the style of Win32) is discouraged, although many places use "m_" or "_" as a prefix for instance variables.
The .NET standard from Microsoft is to use Pascal Case for namespaces, public and protected members (basically anything visible to other classes). For private members and local variables, there's a much wider berth to just do whatever you and your team are most comfortable with.
Don't underestimate the value of following the naming conventions of the platform you are working on as closely as possible.
Look at the reference material for the .NET Framework for examples of how to "fit in" (http://msdn.microsoft.com/en-us/library/ms229335.aspx).
Jon Skeet has given you a link to a good writeup by Microsoft: http://msdn.microsoft.com/en-us/library/ms229042.aspx
You can also use the standalone Microsoft FxCop (or Code Analysis if you have the Team Edition) http://www.microsoft.com/downloads/details.aspx?FamilyID=9aeaa970-f281-4fb0-aba1-d59d7ed09772&DisplayLang=en to check that the naming conventions have been followed. It has built-in rules for the Microsoft conventions, which is another reason you should be using them!
I'd have a look at the slim book called "Elements of C# Style" by Baldwin, Gray, & Misfeldt. The blue book covers naming conventions, and many other aspects of creating consistent, clean, readable code.
Juval Lowy took a stab at this is in Programming .NET Components, see this SO link too.
Resharper's guidelines suggest