Hello World
Console.WriteLine("Hello, world!");
Run the project:
dotnet run
This prints a line to standard output. In a small C# app, Console.WriteLine is the usual starting point.
Variables
string name = "Dan";
int count = 1;
bool active = true;
var language = "C#";
This shows common C# types plus var, which lets the compiler infer the type from the value on the right.
Methods
static string Greet(string name)
{
return $"Hello, {name}!";
}
This is a basic C# method: it accepts an argument, builds a string, and returns the result.