Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Kommentarer | Kom Godt I Gang
Quizzes & Challenges
Quizzes
Challenges
/
C# Grundlæggende

bookKommentarer

In programming, comments are parts of code that are meant for leaving messages, notes or perhaps comments, in the code, for yourself or for other people who might read it. A comment does not affect the functionality of the program.

A single-line comment can be added using the double forward slash (//) operator:

main.cs

main.cs

copy
1234567891011
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { // This is a comment System.Console.WriteLine("Hello World"); } } }

A multi-line comment can be added by enclosing the text inside /* and */ operators.

main.cs

main.cs

copy
1234567891011121314151617
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { /* This is a multi-line comment */ System.Console.WriteLine("Hello World"); } } }

Multi-line comments can also be used to comment out parts of a single line:

main.cs

main.cs

copy
1234567891011
namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine(/*" This text will not be shown." */ "This text will be shown. "); /* System.Console.WriteLine("The whole statement is commented out"); */ } } }

It is also a common practice to comment-out a piece of code which we temporarily want to exclude from the program:

main.cs

main.cs

copy
12345678910111213
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Line 1"); System.Console.WriteLine("Line 2"); // System.Console.WriteLine("Line 3"); System.Console.WriteLine("Line 4"); } } }
question mark

What lines will be included in the output of the following program?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 5

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Can you give examples of single-line and multi-line comments in C#?

Why is it important to use comments in code?

What are some best practices for writing comments in C#?

bookKommentarer

Stryg for at vise menuen

In programming, comments are parts of code that are meant for leaving messages, notes or perhaps comments, in the code, for yourself or for other people who might read it. A comment does not affect the functionality of the program.

A single-line comment can be added using the double forward slash (//) operator:

main.cs

main.cs

copy
1234567891011
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { // This is a comment System.Console.WriteLine("Hello World"); } } }

A multi-line comment can be added by enclosing the text inside /* and */ operators.

main.cs

main.cs

copy
1234567891011121314151617
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { /* This is a multi-line comment */ System.Console.WriteLine("Hello World"); } } }

Multi-line comments can also be used to comment out parts of a single line:

main.cs

main.cs

copy
1234567891011
namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine(/*" This text will not be shown." */ "This text will be shown. "); /* System.Console.WriteLine("The whole statement is commented out"); */ } } }

It is also a common practice to comment-out a piece of code which we temporarily want to exclude from the program:

main.cs

main.cs

copy
12345678910111213
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Line 1"); System.Console.WriteLine("Line 2"); // System.Console.WriteLine("Line 3"); System.Console.WriteLine("Line 4"); } } }
question mark

What lines will be included in the output of the following program?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 5
some-alt