Your first console program
A console program is a program that can write text to standard output, often displayed in a terminal. In modern C#, a console entry point can be written as top-level statements. A statement is an instruction in source code; these examples use statements ending in semicolons.
using System;
Console.WriteLine("Shelf A");Console.WriteLine("Shelf B");The statements execute in order. Each WriteLine call ends its line, so the labels appear on separate lines.
Expected output (not executed here):
Shelf AShelf BRead an output statement
In Console.WriteLine("text");, the parentheses contain an argument: the value passed to the operation. Quotes delimit a string literal, a text value written directly in source. The semicolon ends this statement. To make the short name Console available without relying on project defaults, place using System; before the executable statements. The using directive lets the compiler resolve names in the namespace; it is not an output instruction.
More examples
using System;
Console.WriteLine("2 + 5");Console.WriteLine(2 + 5);The first argument is text because it is inside quotation marks. The second is an arithmetic expression. It evaluates to a number before the method receives it.
Expected output (not executed here):
2 + 57using System;
Console.Write("Shelf ");Console.WriteLine("C");Write does not add a line ending. WriteLine adds one after the second part. Together they create a single line of text.
Expected output (not executed here):
Shelf CWhere this fits
These are complete source-file examples for an ordinary modern console project. The terminal may display additional shell prompts or SDK messages before or after a run; those are not part of the program’s expected output. The code is static in ByteMind for now. Once you have an approved SDK, chapter 2 will explain where the file goes and how to build and run it.
Common mistake
Quotation marks are source syntax, not part of the displayed text. Missing the closing quote or semicolon can cause a compilation error. If you want to display the expression as text, put it inside quotes; if you want its calculated result, leave the arithmetic outside quotes.
Try it yourself
Write two statements that print Returns desk and then the result of 9 - 2 on separate lines. Predict the output before comparing it with the answer key.
Continue with How C# programs execute. The example source is for an ordinary .NET 10 console project; ByteMind C# execution is not established.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Your first console program — knowledge check
Review the concept before moving on.
What is the output of Console.WriteLine("6 + 1");?
Which punctuation ends the example output statement?
What does using System; do in the example?
What appears after Write("A") then WriteLine("B")?