This documentation is archived and is not being maintained.

(1) Hello World

.NET Framework 1.1

First, you will take a look at the simplest .NET Framework application — the traditional Hello World program, written in Visual C# and discussed in detail in the tutorial, Introduction to Developing with the .NET Framework. Here is the Visual C# source code, which can be found with the code accompanying this tutorial in the 1_HelloWorld subdirectory:

// Allow easy reference System namespace classes.
using System;

// This "class" exists only to house entry-point.
class MainApp {
    // Static method "Main" is application's entry point.
    public static void Main() {
        // Write text to the console.
        Console.WriteLine("Hello World using C#!");
    }
}

This stand-alone, executable program writes a single line to System.Console, which is a type contained in the .NET Framework class library. The program does not reference any other libraries and does not itself produce a library. Providing convenient access to types in the .NET Framework class library requires the using statement:

using System;

Also, the program defines a class to enclose the application code:

class MainApp {

Finally, the program defines the Main method to provide the entry point to the code:

public static void Main () {

Build.bat contains the following single line, which is all that is necessary to compile this small program:

csc.exe /debug+ Hello.cs

Running Build.bat generates the stand-alone application named Hello.exe. Running the MSIL Disassembler (Ildasm.exe) against this executable yields a window similar to the following:

Even this simple program illustrates several important concepts behind programming for .NET. First, the program is clearly self-describing; in other words, the information necessary to understand the program is contained in the manifest. Double-clicking the manifest line gives the following additional information:

Here you can see information about the assembly, including the version number (which this simple example does not set), the external libraries that the program uses, and even the types within the libraries that the program uses (in this case, Object and Console).

Running Ildasm.exe also shows the classes, or types, that are created within the program (in this case, the only class is MainApp) as well as the Main method and a default constructor (indicated by .ctor). This simple program does not have other members. Information about the assembly can be saved to a file by selecting Dump from the File menu.

See Also

Deploying Simple Applications | (2) A Simple Componentized Application | (3) Path for Private Components | (4) A Shared Component | (5) Component Versioning | Packaging and Deployment Summary | Appendix A: Additional Packaging and Deployment Information | Appendix B: Packaging and Deployment Tools

Show: