Do not mix coding styles within a group of closely related classes or within a module.

This coding standard gives you some room in choosing a certain style. Do keep the style consistent within a certain scope. That scope is not rigidly defined here, but is at least as big as a source file.

Declare public, protected, and private sections in that order.

Although C# does not have the same concept of accessibility sections as C++, do group them in the given order. However, keep the fields at the top of the class (preferably inside their own #region). The protected internal section goes before the protected section, and the internal section before the private section.

Write operators together with their operands.

This concerns the following operators:

  • unary:                                             & * + – ~ !
  • increment and decrement:                — ++
  • function call and subscript:                () []
  • access:                                                   .

It is not allowed to add spaces in between these operators and their operands.

It is not allowed to separate a unary operator from its operand with a newline.

Note: this rule does not apply to the binary versions of the & * + – operators.

Example:

a = -- b; // bad

a = --c; // good

a = -b - c; // good

a = (b1 + b2) + (c1 - c2) + d – e - f; // also fine: make it as readable as possible

Do not create overly long source lines.

Long lines are hard to read. This standard does not set any explicit limit on the length of a source line, thus leaving the definition of ‘too long’ to groups or projects.

Do put each Parameter in single line

In cases when a method takes many parameters and this conflicts with Section 9.04, then put each parameter in its own line in accordance with the language standards.

        public OrdersController(
            IOrderManager orderManager,
            IUserManager userManager,
            IProjectRepo projectRepo,
            ILogManager logManager)
        {
            ....
        }

Do break up long strings

In the case that a given has a string that makes the line conflicts with Section 9.04, then break up the string into several section/lines or consider putting the string in a recourse file.

Example:
[note that it is hard to show a very long line in a document having a fix document width0]

if (collection.Count == 0)
return NotFound("No items are associated with this order or the order was not found. Before calling this route, make sure that the order exist and that the order contains items.");

Options:

if (collection.Count == 0)
return NotFound("No items are associated with"
+ "this order or the order was not found. Before"
+ "calling this route, make sure that the order"
+ " exist and that the order contains items.");

In C# use a verbatim string literal:
if (collection.Count == 0)
return NotFound(@"No items are associated with
this order or the order was not found. Before
calling this route, make sure that the order
exist and that the order contains items.");

Indentions.

Use the default tabs/spaces for Visual Studio. If writing code outside of Visual Studio, use size 4 for the tab