Is there an official C# code style?
Closed this issue · 3 comments
I wrote my code in my own style different from yours style.
For example i wrote for
loop as:
for (int i = 0; i < 100; i++) {
// some...
}
But you wrote it as:
for (int i = 0; i < 100; i++)
{
// some...
}
Too many different:
- The curly brackets every at new line.
- The indent of 2 spaces instead of 4.
I need some official coding style.
I recommend that you follow the style in Microsoft official documentation. For example, the for
statement, as found at the following link:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/iteration-statements
for (int i = 0; i < 3; i++)
{
Console.Write(i);
}
The reason I use two spaces for indenting is because my code will be printed in a book and therefore has narrow width available.
The official coding style conventions are here:
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions
I have added an improvement item for the current 7th edition here:
https://github.com/markjprice/cs11dotnet7/blob/main/docs/errata/improvements.md#page-56---examples-of-statements-and-blocks
Thank you!