c# coding style guide
by mike krüger icsharpcode.net 【程序编程相关:也来说说C语言】version 0.3 【推荐阅读:MDA,开创大时代 】
this document may be read as a guide to writing robust and reliable programs. it focuses on programs written in c#, but many of the rules and principles are useful even if you write in another programming language. 【扩展信息:WebWork2与SpringFrame】
about the c# coding style guide file organization indentation comments declarations statements white space naming conventions programming practices code examples1. about the c# coding style guide
2. file organization
2.1 c# sourcefiles
keep your classes/files short, don´t exceed 2000 loc, divide your code up, make structures clearer. put every class in a separate file and name the file like the class name (with .cs as extension of course). this convention makes things much easier.
2.2 directory layout
create a directory for every namespace. (for myproject.testsuite.testtier use myproject/testsuite/testtier as the path, do not use the namespace name with dots.) this makes it easier to map namespaces to the directory layout.
3. indentation
3.1 wrapping lines
when an expression will not fit on a single line, break it up according to these general principles: break after a comma. break after an operator. prefer higher-level breaks to lower-level breaks. align the new line with the beginning of the expression at the same level on the previous line
example of breaking up method calls:
longmethodcall(expr1, expr2, expr3, expr4, expr5);examples of breaking an arithmetic expression:
... 下一页