The C# language supports 2 comment syntax forms. Comments do not affect a program's speed. Directives can be used as comments.
The C# language is compiled, which means comments do not affect the executable. It is possible to use directives like #if to insert comments, but this is not ideal.
Here are some comments. We see the C++ style single-line comments. We see the multiline comment syntax used in C programs.
if
-false can be used.using System; class Program { static void Main() { // An example comment. // ... Sometimes indenting comments is helpful too. int value = 10; // Ten. /* A multi-line comment. */ value++; #if false Another way to comment, an #if false directive. #endif value *= 100; Console.WriteLine(value); } }1100
These are part of the C# language specification, but not C# code. The XML comments can be parsed by a code editor (like Visual Studio) and displayed in a window.
using System; class Program { /// <summary> /// Test value and modify it. /// </summary> /// <param name="value">The important value.</param> /// <returns>The modified value.</returns> static int Test(int value) { return value * 2; } static void Main() { Console.WriteLine(Test(2)); } }4
Compilers are logically organized into phases, which are grouped into passes. A lexical parser converts the program text into a series of lexemes (words).
It is usually recommended to describe at the level of intent, not the level of implementation. So you can comment on what the code is supposed to do.
Comments have no effect on the performance of C# programs. There are relevant compiler concepts and style issues. A variety of syntax forms can be used.