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:
Console.Write()
Prints output without moving to a new line.
Output:
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:
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
