For small pieces of logic in your code
// This is inline /* This is multi-line */
int x = 10;
/* This is a multi-line comment
explaining x
*/
// Adding 5 to x
x += 5;
Console.WriteLine(x); // Output will be 15
Using XML comments allows you to generate a XML file that contains your documentation. It is generated by reading your comments that have XML tags.
Specific tags are required to generate a strong XML file:
///<summary> is used to describe the purpose
///<param name=””> is used to describe each parameter
///<returns> is used to describe the return value
Method documentation with inline XML comments ///
/// <summary>
/// Adds two numbers and returns the sum.
/// </summary>
/// <param name="a">The first number.</param>
/// <param name="b">The second number.</param>
/// <returns>The sum of a and b.</returns>
static int Add(int a, int b)
{
return a + b;
}
Class documentation with multi-line XML comments **/
/** <summary>
Represents a simple car with speed control.
</summary>
**/
class Car
{
public string Brand { get; set; }
public int Speed { get; private set; }
/** <summary>
Increases the speed of the car.
</summary>
<param name="amount">The amount to increase the speed.</param>
**/
public void Accelerate(int amount)
{
Speed += amount;
}
}
Describes endpoints, request parameters and responses for web services. These are also XML
[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
/// <summary>
/// Gets user details by ID.
/// </summary>
/// <param name="id">The user ID.</param>
/// <returns>Returns user details if found.</returns>
[HttpGet("{id}")]
public IActionResult GetUser(int id)
{
var user = new { Id = id, Name = "John Doe" };
return Ok(user);
}
}
Seperate simple text file which provides an overview of an entire project. Can include setup instructions, usage and contributers. Usually written in Markdown .md format
# My C# Project
## Description
This project is a simple console application that calculates the sum of two numbers.
## Features
- Takes user input for two numbers
- Displays the sum of the numbers
## Installation
1. Clone this repository:
2. Open the project in **Visual Studio** or **VS Code**.
3. Run the application.
## Usage
1. Run the program.
2. Enter two numbers when prompted.
3. View the sum of the numbers.
## Contributing
Pull requests are welcome! Feel free to submit an issue or suggest improvements.
## License
This project is licensed under the MIT License.