C# · Course navigation

C# Basics

Print a value from a .NET program.

On this page

The concept

Execution starts in Main. Console.WriteLine writes a line to standard output. The using directive makes System types available by short name.

Code example

C#
using System;
class Program {
  static void Main() {
    string name = "Ada";
    Console.WriteLine($"Hello, {name}");
  }
}
Output
Hello, Ada

Follow the code

Open the walkthrough to inspect the example one step at a time.

Show guided walkthrough
Guided walkthroughReady
1using System;
2class Program {
3 static void Main() {
4 string name = "Ada";
5 Console.WriteLine($"Hello, {name}");
6 }
7}

Follow the example

Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.

View the complete dry-run table
Prepared trace of the published program. Some rows group repeated iterations.
Step / lineWhat happensState after stepOutput so far
Create a string variable.name = "Ada"
—
Interpolate name and write the resulting line.name = "Ada"
Hello, Ada

Behind the scenes

How C# processes this code

C# compiles to code for the .NET runtime, which invokes the program entry point.