Basic Program Structure
Part of the Fundamentals section of Coddy's C# journey — lesson 4 of 69.
In C#, code is organized into classes. For now, just know that a class is where you'll write your code - we'll explain more about classes later
The Main method is a crucial part of a C# program because it serves as the starting point of execution.
Here's a simple breakdown of a basic C# program:
using System; // Gives access to Console and other built-in tools
public class Program { // Class declaration
public static void Main(string[] args) { // Main method
Console.WriteLine("Hello, Coddy!"); // Output statement
// Write code inside Main
}
}Notice that using System; appears outside the class — this is normal. using directives always go at the top of the file, before the class declaration. They give your program access to built-in tools like Console.WriteLine.
The indentation (spaces at the start of lines) is used to make the code easier to read — it shows which code belongs inside which block. Code inside the class is indented once, and code inside the Main method is indented again.
You write your code inside the Main method
Important note: In C#, each statement must end with a semicolon (;). The semicolon is mandatory and tells C# that you've reached the end of a statement. Forgetting to add a semicolon will result in a compilation error. However, note that code blocks enclosed in curly braces {} (like class and method declarations) don't need semicolons.
Challenge
BeginnerCreate a C# program with a class named Program that contains the Main method. Inside the Main method, write code to output the following text:
This is my first C# program!Try it yourself
using System;
public class Program {
// 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