Variables Flashcards

(11 cards)

1
Q

What are comments in C#?

A

Comments in C# are non-executable text used to annotate code for better understanding and maintainability. They are ignored by the compiler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the syntax for single-line comments in C#?

A

The syntax for single-line comments is //.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are single-line comments used for?

A

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
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the syntax for multi-line comments in C#?

A

The syntax for multi-line comments is /* */.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are multi-line comments used for?

A

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 */
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the syntax for XML documentation comments in C#?

A

The syntax for XML documentation comments is ///.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are XML documentation comments used for?

A

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;
}
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Does C# support nested comments?

A

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
*/
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some commenting best practices in C#?

A

Use comments to explain why something is done, avoid over-commenting, keep comments up-to-date, and use XML documentation for public APIs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How are comments used to comment out code?

A

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”);
*/
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are special comment tags used for?

A

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
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly