C# Comments
C# Comments
Comments can be used to explain C# code, and to make it more readable. It can also be used to prevent execution when testing alternative code.
Single-line Comments
Single-line comments start with two forward slashes (//
).
Any text between //
and the end of the line is ignored by C# (will not be executed).
This example uses a single-line comment before a line of code:
This example uses a single-line comment at the end of a line of code:
C# Multi-line Comments
Multi-line comments start with /*
and ends with */
.
Any text between /*
and */
will be ignored by C#.
This example uses a multi-line comment (a comment block) to explain the code:
Example
/* The code below will print the words Hello World
to the screen, and it is amazing */
Console.WriteLine("Hello World!");
Single or multi-line comments?
It is up to you that you want to use. Normally, we use //
for short comments, and /* */
for longer.
C# Exercises
TOP-10 most popular extensions for Visual Studio Code used when programming in the C# language:
- C# - is an official C# development extension from Microsoft. It provides support for IntelliSense, refactoring, debugging, and more.
- C# Dev Kit - the C# Dev Kit helps you manage your code with Solution Explorer and test your code with integrated discovery and unit test execution, improving your C# development experience wherever you want to develop (Windows, macOS, Linux, and even in Codespace).
- C# XML Documentation Comments - is an extension that adds support for XML comments for documenting C# code.
- C# Snippets - this extension for Visual Studio Code adds code snippets for C# to help speed up the code writing process.
- C# Extensions - is an extension that provides advanced C# development capabilities, including support for .NET Core and ASP.NET Core.
- Auto-Using for C# - is an extension that automatically imports and provides intellisense for references that have not yet been imported into a C# file.
- C# Namespace Autocompletion - is an extension that does full namespace autocompletion for C#.
- NuGet Package Manager - this extension makes it easy to install and manage NuGet packages.
- Unity - is an extension that allows you to debug Unity code in Visual Studio Code.
- Code Runner - is an extension that allows you to execute C# code directly from Visual Studio Code.
- CSharpier - Code formatter - is an extension that automatically formats C# code according to established rules.
Information provided by ChatGPT