Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Displaying Output | Getting Started
C# Basics

bookDisplaying Output

メニューを表示するにはスワイプしてください

We can use the System.Console.WriteLine method to display some text in the console. Following is the syntax for doing that:

main.cs

main.cs

copy
1
System.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

main.cs

copy
12345678910
namespace 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

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."); } } }

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

main.cs

copy
1234567891011
namespace 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

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

Complete the code:

.()
Output Text

クリックまたはドラッグ`n`ドロップして空欄を埋めてください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  3

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  3
some-alt