Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Visning af Output | Kom Godt I Gang
C# Grundlæggende

bookVisning af Output

Vi kan bruge metoden System.Console.WriteLine til at vise tekst i konsollen. Følgende er syntaksen for dette:

main.cs

main.cs

copy
1
System.Console.WriteLine("message to output");

Bemærk, at vi omslutter teksten med dobbelte anførselstegn ("). I C# er alle tekstdata altid omsluttet af dobbelte anførselstegn.

main.cs

main.cs

copy
12345678910
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Some text to output in the console."); } } }

Metoden System.Console.WriteLine flytter automatisk markøren til næste linje, så hvis vi bruger System.Console.WriteLine igen, vil teksten blive vist på en ny linje.

main.cs

main.cs

copy
1234567891011
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("This is the first line."); System.Console.WriteLine("This is the second line."); } } }

En anden metode til at vise beskeder i konsollen er System.Console.Write. Den ligner metoden System.Console.WriteLine. Dog flytter den ikke markøren til næste linje.

main.cs

main.cs

copy
1234567891011
namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.Write("World!"); } } }

Forskellen mellem de to metoder bliver tydeligere med et eksempel:

main.cs

main.cs

copy
123456789101112
namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.WriteLine("World!"); System.Console.Write("A new line!"); } } }
question-icon

Fuldfør koden:

.()
Output Text

Click or drag`n`drop items and fill in the blanks

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 3

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

Awesome!

Completion rate improved to 1.59

bookVisning af Output

Stryg for at vise menuen

Vi kan bruge metoden System.Console.WriteLine til at vise tekst i konsollen. Følgende er syntaksen for dette:

main.cs

main.cs

copy
1
System.Console.WriteLine("message to output");

Bemærk, at vi omslutter teksten med dobbelte anførselstegn ("). I C# er alle tekstdata altid omsluttet af dobbelte anførselstegn.

main.cs

main.cs

copy
12345678910
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Some text to output in the console."); } } }

Metoden System.Console.WriteLine flytter automatisk markøren til næste linje, så hvis vi bruger System.Console.WriteLine igen, vil teksten blive vist på en ny linje.

main.cs

main.cs

copy
1234567891011
namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("This is the first line."); System.Console.WriteLine("This is the second line."); } } }

En anden metode til at vise beskeder i konsollen er System.Console.Write. Den ligner metoden System.Console.WriteLine. Dog flytter den ikke markøren til næste linje.

main.cs

main.cs

copy
1234567891011
namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.Write("World!"); } } }

Forskellen mellem de to metoder bliver tydeligere med et eksempel:

main.cs

main.cs

copy
123456789101112
namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.WriteLine("World!"); System.Console.Write("A new line!"); } } }
question-icon

Fuldfør koden:

.()
Output Text

Click or drag`n`drop items and fill in the blanks

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 3
some-alt