Ausgabe Anzeigen
We can use the System.Console.WriteLine method to display some text in the console. Following is the syntax for doing that:
main.cs
1System.Console.WriteLine("message to output");
Note that we enclose the text in double-quotes ("). In C#, any textual data is always enclosed in double-quotation marks.
main.cs
12345678910namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Some text to output in the console."); } } }
The System.Console.WriteLine method automatically shifts the cursor to the next line so if we use System.Console.WriteLine again, the text will be outputted in a new line.
main.cs
1234567891011namespace 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."); } } }
Another method for outputting messages in the console is System.Console.Write. It is similar to the System.Console.WriteLine method. However, it does not shift the cursor to the next line.
main.cs
1234567891011namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.Write("World!"); } } }
The difference between the two methods might become more clear with an example:
main.cs
123456789101112namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.WriteLine("World!"); System.Console.Write("A new line!"); } } }
Danke für Ihr Feedback!
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Awesome!
Completion rate improved to 1.59
Ausgabe Anzeigen
Swipe um das Menü anzuzeigen
We can use the System.Console.WriteLine method to display some text in the console. Following is the syntax for doing that:
main.cs
1System.Console.WriteLine("message to output");
Note that we enclose the text in double-quotes ("). In C#, any textual data is always enclosed in double-quotation marks.
main.cs
12345678910namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Some text to output in the console."); } } }
The System.Console.WriteLine method automatically shifts the cursor to the next line so if we use System.Console.WriteLine again, the text will be outputted in a new line.
main.cs
1234567891011namespace 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."); } } }
Another method for outputting messages in the console is System.Console.Write. It is similar to the System.Console.WriteLine method. However, it does not shift the cursor to the next line.
main.cs
1234567891011namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.Write("World!"); } } }
The difference between the two methods might become more clear with an example:
main.cs
123456789101112namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.WriteLine("World!"); System.Console.Write("A new line!"); } } }
Danke für Ihr Feedback!