Basic Output
Part of the Fundamentals section of Coddy's C# journey — lesson 31 of 69.
In C#, you can display output to the console using the System.Console.WriteLine method. This method prints text or values to the console and moves to a new line afterward.
System.Console.WriteLine("Hello, world!");
System.Console.WriteLine(42);Output:
Hello, world!
42The System.Console.WriteLine method can handle different data types, including strings, numbers, and even variables.
Using System Namespace:
The Console class belongs to the System namespace. At the start of your program, ensure you include:
using System;This makes the Console class available without needing to write System.Console every time.
Now you can use Console.WriteLine to create interactive and engaging outputs in your programs!
Challenge
BeginnerWrite a C# program that uses Console.WriteLine to output the following:
- Print
"Hello, Coddy!"on a new line. - Print
"C# is fun!"on a new line.
Cheat sheet
To display output to the console in C#, use the System.Console.WriteLine method:
Console.WriteLine("Hello, world!");
Console.WriteLine(42);The System.Console.WriteLine method prints text or values and moves to a new line afterward. It can handle different data types including strings, numbers, and variables.
Include the System namespace at the start of your program:
using System;This allows you to use Console.WriteLine without writing System.Console every time.
Try it yourself
using System;
public class Program {
public static void Main(string[] args) {
// Write your code here
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic Shortcuts5Operators Part 2
Comparison OperatorsLogical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3