Back

Foundation: Console Basics

divider

Foundation Activity

Console Basics

An Optional First Step

This activity gives you a slower first pass at writing, running, and changing C# before you work in a Raylib window.

Use it before Activity 1.2 or return to it whenever you want more practice.

Key Concepts

Writing and Running Instructions

Console Output, Strings, and Comments

Two Kinds of Programs

Console

Runs from top to bottom, displays text, and ends.

Game

Opens a window and repeats until the window closes.

Start With the Console

The console makes each instruction and its result easy to see. You can focus on one new idea at a time.

Display One Line

Demo
Console.WriteLine("Hello, world!");
Demo
Hello, world!

Read the Statement

Demo
Console.WriteLine("Hello, world!");
  1. Console.WriteLine performs the action.
  2. The parentheses hold information for the action.
  3. The quotation marks surround the text.
  4. The semicolon ends the statement.

Strings Are Text Values

A string is text surrounded by quotation marks. The quotation marks tell C# where the text begins and ends.

The quotation marks are part of the code. They are not printed in the terminal.

Instructions Run in Order

Demo
Console.WriteLine("First instruction");
Console.WriteLine("Second instruction");
Console.WriteLine("Third instruction");
Demo
First instruction
Second instruction
Third instruction

Print a Blank Line

Use Console.WriteLine(); with nothing inside the parentheses to print an empty line.

Blank lines can make longer output easier to read.

Comments

Comments serve two useful roles:

  • Explaining the code to a human reader
  • Temporarily disabling a line while testing

Comments

A single-line comment begins with //. C# ignores everything after the slashes on that line.

Demo
// This comment explains the next instruction.
Console.WriteLine("This line runs.");
// Console.WriteLine("This line is temporarily disabled.");
Console.WriteLine("This line also runs.");
Demo
This line runs.
This line also runs.

Errors Are Feedback

Broken Demo
Console.WriteLine("Hello, world!);

A missing quotation mark prevents C# from understanding where the string ends. Read the error, inspect the line, and repair it.

Today's Objectives

  • Writing and running C# statements
  • Displaying console output
  • Printing strings and blank lines
  • Reading and writing comments

Key Terms

Statement
One instruction for the computer to carry out.
Console Output
Text that a program displays in a terminal.
String
A text value surrounded by quotation marks.
Comment
A note in the source code that C# ignores.
Syntax
The rules for writing valid code in a language.

'F' → Fullscreen

divider

Build

In the downloaded workspace, copy template-console and name the copy fb-console-basics. Open itsProgram.cs file.

Protect the template. Always work in a copy so template-console stays clean for future activities.


Task 1: Write and Test

  • Replace the starter code with the program below.
  • Type each statement carefully, including its punctuation.
  • Click the triangular Run Code play button at the top right of the editor.
  • Compare the terminal output with the strings in your code.
CONSOLE BASICS
Console.WriteLine("Hello, world!");
Console.WriteLine("C# programs run from top to bottom.");
Console.WriteLine();

Task 2: Add More Output

  • Add the new section beneath your current code.
  • Run the program and check the order of all displayed lines.
  • Find both Console.WriteLine(); statements and identify the blank lines they create.
CONSOLE BASICS
Console.WriteLine("Hello, world!");
Console.WriteLine("C# programs run from top to bottom.");
Console.WriteLine();
Console.WriteLine("A console program can display several lines.");
Console.WriteLine("Each statement ends with a semicolon.");
Console.WriteLine();
Console.WriteLine("Run often so mistakes are easier to find.");

Task 3: Read and Use a Comment

  • Add the comment and disabled output statement shown below.
  • Run the program. The disabled line should not appear.
  • Remove only the first two slashes from the disabled Console.WriteLine statement.
  • Run again and confirm that the new sentence appears.
CONSOLE BASICS
Console.WriteLine("Hello, world!");
Console.WriteLine("C# programs run from top to bottom.");
Console.WriteLine();
Console.WriteLine("A console program can display several lines.");
Console.WriteLine("Each statement ends with a semicolon.");
Console.WriteLine();
// This line is ready, but it is temporarily disabled.
// Console.WriteLine("Comments can turn a line off.");
Console.WriteLine("Run often so mistakes are easier to find.");

Task 4: Predict the Order

  1. Choose any two output statements.
  2. Predict how the terminal will change if you swap their order.
  3. Swap the statements and run the program.
  4. Restore the program so it matches the checkpoint output.

Challenge (Optional): Make a Text Banner

  • Add a school-appropriate title made from at least three lines.
  • Use repeated keyboard characters to create a border.
  • Add one comment that explains your custom section.
divider

Checkpoint

Uncomment the required statement, run your program, and compare it with this output. Your optional banner may add extra lines.

Example Output
Hello, world!
C# programs run from top to bottom.
A console program can display several lines.
Each statement ends with a semicolon.
Comments can turn a line off.
Run often so mistakes are easier to find.
divider

Reflection

Answer the following questions after checking your program.

  1. What does Console.WriteLine do, and what information goes inside its parentheses?
  2. What would you inspect first if C# reported an error on a line containing a string?
  3. How does swapping two statements change the program's output?
divider

Submit

Keep your working project. This Foundation activity has no separate submission unless your instructor asks to see it.

Foundation Activity Complete