C-SHARP - 1.4 My first program(2/2)
This video walks through the default Visual Studio project that was created for us. On the right is the solution explorer, with a Program.cs file (CS stands for C#). When you create a new project, Visual Studio scaffolds this file and fills it with some boilerplate code. The wrapper element is the solution, which is a container that can hold multiple projects — for example, you could right-click the solution and add another project to ship an iOS or Android app alongside this one. For now we only need a single project, ProjectCS.
The Dependencies node lists the frameworks the program relies on — here Microsoft.NETCore.App. This standard library is what gives us functions like Console.WriteLine. We type our code in the editor, click the green Play button and the program runs in a console window. The default program prints Hello World by calling Console.WriteLine("Hello World");. Console.WriteLine is a function: it takes whatever you pass between the parentheses (the parameter) and writes it to the output, followed by a line break.
Anatomy of the default program
- Entry point:
static void Main()is where execution begins — every language has an equivalentMain. - Braces:
{ ... }delimit a block of code. The compiler does not care about indentation in C# (unlike Python). - Instructions: every statement ends with a
;. You can write multiple statements on one line or split them — the result is the same. - Errors are explicit: forget a
;or a brace and the compiler points to the exact line that fails.
If you copy/paste Console.WriteLine("Hello World"); twice, the program prints the message twice. Replace WriteLine with Write and the line break disappears: outputs run together. Forget the semicolon and the compiler refuses to build, displaying ; expected on line N — click the error and Visual Studio jumps straight to the offending line. The takeaway: code is unforgiving and precise, but Visual Studio guides you to fix the small typos every developer (even senior ones) makes. With this baseline you can start exploring more advanced features.
Summary
This lesson continues your introduction to C# programming by exploring the Visual Studio interface and the default code structure generated when you create a new project. You learn how Console.WriteLine() works as a function to display output, understand the Main() function as the program's entry point, and discover that code formatting doesn't affect execution—only the actual instructions and their parameters do. Through practical examples of copying and modifying the Console.WriteLine() calls, you see how small changes to your code directly impact the program's output.
Key points
- Visual Studio automatically creates a Solution (container) with a Project inside, and generates a default Program.CS file with boilerplate code
- The Main() function is the entry point where your program execution begins; all code between its curly braces { } will execute
- Console.WriteLine() is a function that displays text to the output window and automatically includes a line break after the text
- In C#, code indentation and line breaks don't affect the program's output—only the actual function calls and their parameters matter
- Every instruction in C# must end with a semicolon (;) so the compiler knows when one instruction ends and another begins
- The dependencies (frameworks) listed in your project define which tools your program can use, such as the Console class for displaying output
FAQ
What's the difference between a Solution and a Project in Visual Studio?
A Solution is a container that groups multiple projects together, while a Project is the actual C# code module inside it. This lets you organize multiple related programs under one solution if needed.
Why does 'Hello World' appear when I click the play button?
The default code includes the line Console.WriteLine("Hello World"); inside the Main() function. When you run the program, this instruction executes and displays 'Hello World' in the output window.
What happens if I don't use WriteLine in Console.Write()?
Console.Write() displays text without a line break after it, so multiple console commands will display on the same line. Console.WriteLine() includes a line break (the 'Line' part) after each text output.