1.1. A First C# Program

The traditional first program in a new language is one that prints Hello, World! on the user's console. In C# this program is implemented as follows:

// our first C# program
using System;
class Hello
      public static void Main()
             Console.WriteLine( "Hello, World!" );

When compiled and executed, this code generates the canonical

Hello, World!

Our program consists of four elements: (1) a comment, introduced by the double slash (//), (2) a using directive, (3) a class definition, and (4) a class member function (alternatively called a class method) named Main().

A C# program begins execution in the class member function Main(). This is called the program entry point. Main() must be defined as static. In our example, ...

Get C# Primer: A Practical Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.