C# Syntax
C# syntax defines how programs are structured: statements end with a semicolon, and blocks of code are grouped using curly braces. C# is case-sensitive, so `Total` and `total` are different identifiers.
C# code is organized into namespaces, classes, and methods. Understanding this structure early makes it much easier to read and write larger programs later.
class Program {
static void Main() {
statement1;
statement2;
}
}Statements and blocks
Each instruction (a statement) ends with a semicolon. Related statements are grouped into a block using curly braces, such as the body of a method or an if statement.
Identifiers and case sensitivity
Names for variables, methods and classes can contain letters, digits and underscores but cannot start with a digit. C# distinguishes uppercase from lowercase letters.
using System;
class Program {
static void Main() {
int age = 25;
Console.WriteLine("Age: " + age);
}
}Age: 25A block is enclosed in braces, and each statement ends with a semicolon.
using System;
class Program {
static void Main() {
int Age = 1;
int age = 2;
Console.WriteLine(Age + " " + age);
}
}1 2Age and age are treated as two different variables because C# is case-sensitive.
Key points
- Statements end with a semicolon.
- Curly braces { } group statements into blocks.
- C# is case-sensitive.
- Code is organized into namespaces, classes, and methods.
