C# Basics

Print a value from a .NET program.

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

Explanation

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

Explore the dry run
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