开发者

C# style prefered spacing between regions, between methods, and between properites [closed]

开发者 https://www.devze.com 2022-12-18 02:47 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this pos开发者_Go百科t.

Closed 4 years ago.

Improve this question

what is considered best practice from a code readability standpoint regarding spacing?

Are there any really good C# style guides out there?


A good, short, practical one is here: http://blogs.msdn.com/kirillosenkov/archive/2009/03/12/kirill-s-whitespace-guidelines-for-c.aspx

In short, have the amount of whitespace that is easy on eye. In C#, you'll have less whitespace than in some other languages because many lines consist only of curly braces. Leaving no blank lines can still result in plenty of white space. I also like to keep very related lines of code right up next to each other, making paragraphs in a sense.

There one reason for taking out blank lines that's not okay: to fit more code on your screen. If you're doing that, your code is probably not organized well, with functions too long.


Checkout StyleCop It analyzes your code for MS standards


The best document on C# coding style I have seen is Lance Hunt's C# coding standards document, which can be found here:

http://weblogs.asp.net/brijmohan/archive/2008/10/10/c-coding-standards-by-lance-s.aspx

As far as whitespacing goes specifically, I am of the opinion that you use your own best judgement with respect to readability, although Krill's guide (mentioned in one of the other answers) is very representative of good whitespace style.

0

精彩评论

暂无评论...
验证码 换一张
取 消