Page:
C# Coding Convention
Pages
API SMHI
API TimeEdit
Accessibility Testing
Api documentation
Bat/Ps
Branch Creation
C# Coding Convention
CSS Coding Convention
Coding Conventions
Creating new databases
Dapper
Documentation for service endpoints
Documentation of useTemperature and mock sensor
Energy endpoints
Environment
Evaluation react-grid-layout
Evaluation Localization
Evaluation Password hashing
Evaluation Testing framework
Evaluation of Logging Frameworks
Formatter
Frontend model
Generic Diagram for Sensor data flow
Home
How to- Creating Databases in Docker
Implementing different Styles
Implementing new Mockup sensors
Implementing new Views
Installation script documentation
Installation
Issues
JSON Coding Convention
Jest Testing
Layout endpoints
Linux
Localization
Login endpoints
Mac
Middleware model
Mock API Ceation Guidelines
Mockup models
Model Tools and Standards
Parking endpoints
React/JavaScript Coding Convention
React
Reviews
Room booking endpoints
SQL Coding Convention
Scheduled Database tasks
Scripting Coding Convention
Secrets and .env
Server Access
Server-Deployment
Service/API models
System models
System requirements
Temperature endpoints
Testing API with Bruno
Testing Architecture
Testing frontend for Mobile devices
Testing frontend with Playwright
Testing methodology
Västtrafik API
Webpage Design
Windows
pg_cron and scheduled database jobs
xUnit Testing
No results
16
C# Coding Convention
Tim Svensson edited this page 2026-04-24 13:04:50 +00:00
Table of Contents
C# Coding Convention
If coding conventions for a specific part is not documented here, please refer to Common C# code conventions
Naming Conventions
- Use PascalCase for class names and method names.
- Use camelCase for method arguments, local variables, and private fields.
- Use PascalCase for constant names, both fields and local constants.
- Interface names start with a capital I
Layout
- Write only one statement per line.
- Write only one declaration per line.
- If continuation lines aren't indented automatically, indent them one tab stop (four spaces).
- Add at least one blank line between method definitions and property definitions.
- Use parentheses to make clauses in an expression apparent, as shown in the following code.
if ((startX > endX) && (startX > previousX))
{
// Take appropriate action.
}
Comments
- Use single-line comments (//) for brief explanations.
- Avoid multi-line comments (/* */), should only be used for longer explanations where necessary.
- Comments in the code samples aren't localized. That means explanations embedded in the code aren't translated. Longer, explanatory text should be placed in the companion article, so that it can be localized.
- For describing methods, classes, fields, and all public members use XML comments.
- Place the comment on a separate line, not at the end of a line of code.
- Begin comment text with an uppercase letter.
- End comment text with a period.
- Insert one space between the comment delimiter (//) and the comment text, as shown in the following example.
Example:
/// <summary>
/// This class shows the coding standard, and some examples of what not to do.
/// </summary>
class HelloWorldProgram
{
/// <summary>
/// The classes main function.
/// Declares constants and then calls upon CoolMath method.
/// Outputs resulting value from the CoolMath method.
/// </summary>
/// <param name="args">A string array that can take diverse arguments.</param>
static void Main(string[] args)
{
const int VarX = 5; const int VarY = 10;
// Bad way to declare two constants, should be two lines.
string outPut = CoolMath(VarX, VarY);
Console.WriteLine(outPut);
}
/// <summary>
/// A method to show coding standards and print hello world.
/// It compares varX with varY and 0, and if within limits it prints "Hello world!"
/// Otherwise it prints "Nothing here."
/// </summary>
/// <param name="varX">An int that gets compared with 0 and varY.</param>
/// <param name="varY">An int that gets compared with varX.</param>
/// <returns>Returns a string with either "Hello world!" or "Nothing here."</returns>
static string CoolMath(int varX, int varY)
{
string coolName = "Hello world!";
if ((varX < varY) && (varX > 0))
{
return (coolName);
}
else
{
return "Nothing here.";
}
}
}
1. Setup
2. Standards
- Coding Conventions
- Issues
- Branch creation
- Reviews
- Implementation Standards
- [WIP] Creating new databases
- Localization
3. Models and Diagrams
4. Testing
5. Documentation
- Documentation for service endpoints
- API documentation
- Webpage Design
- Secrets and .env
- Evaluations
- Installation and Rebuild script documentation
6. Guides and How-to's
7. Micro Service Mockup Api
- Guidelines Mircro Service Mockup
- Documentation of useTemperature/useTemperatureTimeSeries mockup sensor