Variables Flashcards
(11 cards)
What are comments in C#?
Comments in C# are non-executable text used to annotate code for better understanding and maintainability. They are ignored by the compiler.
What is the syntax for single-line comments in C#?
The syntax for single-line comments is //
.
What are single-line comments used for?
Single-line comments are used for short explanations or notes on a single line.
Example:
```csharp
// This is a single-line comment
int x = 10; // Initialize x with value 10
~~~
What is the syntax for multi-line comments in C#?
The syntax for multi-line comments is /* */
.
What are multi-line comments used for?
Multi-line comments are used for longer explanations or commenting out multiple lines of code.
Example:
```csharp
/* This is a multi-line comment.
It can span multiple lines. /
int y = 20; / This is also a comment */
~~~
What is the syntax for XML documentation comments in C#?
The syntax for XML documentation comments is ///
.
What are XML documentation comments used for?
XML documentation comments are used to generate XML documentation for the code, which can be used by tools like Visual Studio.
Example:
```csharp
/// <summary>
/// This method adds two integers.
/// </summary>
/// <param></param>The first integer.</param>
/// <param></param>The second integer.</param>
/// <returns>The sum of the two integers.</returns>
public int Add(int a, int b)
{
return a + b;
}
~~~
Does C# support nested comments?
C# does not support nested multi-line comments. Attempting to nest /* */
comments will result in a compilation error.
Example (invalid):
```csharp
/* Outer comment
/* Inner comment */ // This will cause an error
*/
~~~
What are some commenting best practices in C#?
Use comments to explain why something is done, avoid over-commenting, keep comments up-to-date, and use XML documentation for public APIs.
How are comments used to comment out code?
Comments are often used to temporarily disable code during debugging or testing.
Example:
```csharp
// int z = 30; // This line is commented out
/*
Console.WriteLine(“This code is disabled”);
*/
~~~
What are special comment tags used for?
Special comment tags like TODO
, FIXME
, and NOTE
are used to mark tasks or issues in the code.
Example:
```csharp
// TODO: Implement this method later
// FIXME: This logic is broken
// NOTE: This is a workaround for issue #123
~~~