Section 1.8. Your First Program: Hello World


1.8. Your First Program: Hello World

In this first example, you will create a very simple application that does nothing more than display the words "Hello World" to your monitor. This console application is the traditional first program for learning any new language; it demonstrates some of the basic elements of a C# program.

Once you write your "Hello World" program and compile it, this chapter will provide a line-by-line analysis of the source code. This analysis gives something of a preview of the language; Chapter 3 describes the fundamentals much more fully.

As explained earlier, you can create C# programs with any text editor. You can, for example, create each of the three programs shown previously (in Figures 1-1, 1-2, and 1-3) with Notepad. To demonstrate that this is possible, you'll write your very first C# program using Notepad.

Begin by opening Notepad and typing in the program exactly as shown in Example 1-2.

Example 1-2. Hello World in Notepad
 namespace NotePad {    class HelloWorld    {       // every console app starts with Main       static void Main(  )       {          System.Console.WriteLine("Hello world!");       }    } } 

That is the entire program. Save it to your disk as a file called helloworld.cs .

We'll examine this program in some detail in just a moment. First, however, it must be compiled.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net