C# Output

C# Output

In C#, output is used to display text or data to the user. This is mainly done using the Console class.


 Console.WriteLine()

Prints output and moves to a new line.


Output:

Hello World
Welcome to C#

 Console.Write()

Prints output without moving to a new line.


Output:

Hello C#

 Printing Variables


 


 Combine Text and Variables

✔ Using + Operator



✔ Using String Interpolation (Recommended)



✔ Using Placeholders


 


 Escape Characters

Escape Meaning
\n New line
\t Tab
\" Double quote
\\ Backslash


 Print Numbers and Calculations



 Formatting Output


Output:

Price: 99.99

 Output Without Console (Advanced)

Used in GUI/Web apps:

  • MessageBox.Show() (Windows Forms)

  • Response.Write() (ASP.NET)

  • return View() (MVC)


Summary

Console.WriteLine() → new line
Console.Write() → same line
✔ String interpolation is best
✔ Supports formatted output

You may also like...