C# Syntax
Read a C# file by its scopes and use comments to explain a workshop rule rather than every token.
How it works
A declaration introduces a name and type, while statements perform work or choose control flow. Braces create blocks and define where local names can be used. Identifiers are case-sensitive, so places and Places are different names. A comment explains why a rule exists but does not enforce it. Use a named constant for a stable policy and keep its explanation close to the calculation. If the rule changes, update the source and its tests together so an old comment does not mislead a maintainer.
Run it locally
Use the .NET 10 SDK with C# 14 in a separate console lab. Create an empty project once with dotnet new console --framework net10.0, then replace Program.cs with this complete source and add any supporting files shown. Keep only one lesson entry point in the project. C# does not currently run in Bhylu’s browser playground. Apache, PHP and MySQL are not needed.
dotnet build -p:LangVersion=14.0 -p:Nullable=enable -p:TreatWarningsAsErrors=true
dotnet run --no-buildUse the SDK’s project workflow; the review compiles against its matching reference assemblies and executes the results without external NuGet packages. File-writing examples belong in a private empty lab directory.
Example
using System;
internal static class Program
{
private static void Main(string[] args)
{
int available = 12;
{
// Keep two places for the workshop helpers.
const int helperPlaces = 2;
available -= helperPlaces;
}
Console.WriteLine($"Public places: {available}");
}
}
Expected result
Public places: 10
available remains visible through Main, while helperPlaces belongs to the nested block. The compound assignment updates an existing variable. Semicolons end these statements; indentation makes their relationships easier for a person to read. A using directive makes a namespace’s type names available without repeating the namespace prefix every time.
Consult Microsoft’s C# documentation for language and library contracts, including target-framework and version requirements.