CHASH Tutorial



C# OUTPUT


Output in C#

In C#, output is commonly displayed to the console using the Console.WriteLine() and Console.Write() methods.

1. Console.WriteLine()

This method prints the text followed by a newline (moves to the next line):

Console.WriteLine("Hello, World!");
Console.WriteLine("Welcome to C# programming.");

  

2. Console.Write()

This prints the text without adding a new line after it, so the next output continues on the same line:

Console.Write("Enter your name: ");
Console.Write("John");

  

3. Outputting Variables

You can output variable values by concatenating them with strings using the + operator:

string name = "Alice";
int age = 25;
Console.WriteLine("Name: " + name);
Console.WriteLine("Age: " + age);

  

4. String Interpolation (Recommended)

String interpolation makes it easier to embed variables inside strings:

Console.WriteLine($"Name: {name}");
Console.WriteLine($"Age: {age}");

  

5. Formatting Output

You can format numbers, dates, and more using format strings:

double price = 123.456;
Console.WriteLine($"Price: {price:F2}");  // Outputs price with 2 decimal places

  

Summary

  • Console.WriteLine() prints text and moves to a new line.
  • Console.Write() prints text without moving to a new line.
  • Use string concatenation or string interpolation to display variable values.
  • Format output easily using format specifiers inside interpolated strings.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review