Exibindo Saída
Podemos usar o método System.Console.WriteLine
para exibir um texto no console. A seguir está a sintaxe para isso:
main.cs
1System.Console.WriteLine("message to output");
Observe que o texto é colocado entre aspas duplas ("
). Em C#, qualquer dado textual deve sempre estar entre aspas duplas.
main.cs
12345678910namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Some text to output in the console."); } } }
O método System.Console.WriteLine
move automaticamente o cursor para a próxima linha, portanto, se utilizarmos System.Console.WriteLine
novamente, o texto será exibido em uma nova linha.
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."); } } }
Outro método para exibir mensagens no console é o System.Console.Write
. Ele é semelhante ao método System.Console.WriteLine
. No entanto, ele não move o cursor para a próxima linha.
main.cs
1234567891011namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.Write("World!"); } } }
A diferença entre os dois métodos pode ficar mais clara com um exemplo:
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!"); } } }
Obrigado pelo seu feedback!
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Can you show me an example demonstrating the difference between Write and WriteLine?
What happens if I use Write and WriteLine together in sequence?
Can you explain when to use Write vs WriteLine?
Awesome!
Completion rate improved to 1.59
Exibindo Saída
Deslize para mostrar o menu
Podemos usar o método System.Console.WriteLine
para exibir um texto no console. A seguir está a sintaxe para isso:
main.cs
1System.Console.WriteLine("message to output");
Observe que o texto é colocado entre aspas duplas ("
). Em C#, qualquer dado textual deve sempre estar entre aspas duplas.
main.cs
12345678910namespace TestConsoleApp { internal class Program { static void Main(string[] args) { System.Console.WriteLine("Some text to output in the console."); } } }
O método System.Console.WriteLine
move automaticamente o cursor para a próxima linha, portanto, se utilizarmos System.Console.WriteLine
novamente, o texto será exibido em uma nova linha.
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."); } } }
Outro método para exibir mensagens no console é o System.Console.Write
. Ele é semelhante ao método System.Console.WriteLine
. No entanto, ele não move o cursor para a próxima linha.
main.cs
1234567891011namespace ConsoleApp { internal class Program { static void Main(string[] args) { System.Console.Write("Hello, "); System.Console.Write("World!"); } } }
A diferença entre os dois métodos pode ficar mais clara com um exemplo:
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!"); } } }
Obrigado pelo seu feedback!