Examining Your First Program

The single greatest challenge when learning to program is that you must learn everything before you can learn anything. Even this simple “Hello World” program uses many features of the language that will be discussed in coming chapters, including classes, namespaces, statements, static methods, objects, strings, inheritance, blocks, libraries, and even something called polymorphism!

It is as if you were learning to drive a car. You must learn to steer, accelerate, brake, and understand the flow of traffic. Right now we’re going to get you out on the highway and just let you steer for a while. Over time you’ll learn how to speed up and slow down. Along the way you’ll learn to set the radio and adjust the heat so that you’ll be more comfortable. In no time you’ll be driving, and then won’t your parents begin to worry.

Line-by-Line Analysis

Hang on tight, we’re going to zip through this quickly and come back to the details in subsequent chapters.

The first line in the program defines a namespace:

               namespace NotePad

You will create many names when programming in C#. Every object and every type of object must be named. It is possible for the names you assign to conflict with the names assigned by Microsoft or other vendors. A namespace is a way to say “these names are mine.”

In this program, you’ve created a namespace called NotePad. Each namespace must be enclosed in braces ({}). Thus, the second line of the Hello World program is an open brace to mark the ...

Get Learning C# now with O’Reilly online learning.

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