Hello World Sample

This sample shows several versions of a Hello World program in C#.

Security Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To build and run the Hello World samples within Visual Studio

  1. Open the solution (HelloWorld.sln).

  2. In Solution Explorer, right-click the HelloWorld1 project and click Set as StartUp Project.

  3. From the Debug menu, click Start Without Debugging.

  4. Press any key to close HelloWorld1.

  5. In Solution Explorer, right-click the HelloWorld2 project and click Set as StartUp Project.

  6. From the Debug menu, click Start Without Debugging.

  7. Press any key to close HelloWorld2.

  8. In Solution Explorer, right-click the HelloWorld3 project and click Set as StartUp Project.

  9. In Solution Explorer, right-click the HelloWorld3 project and click Properties.

  10. Open the Configuration Properties folder, and click Debug.

  11. In the Command Line Arguments property, type "A B C D" and click OK.

  12. From the Debug menu, click Start Without Debugging.

  13. Press any key to close HelloWorld3.

  14. In Solution Explorer, right-click the HelloWorld4 project and click Set as StartUp Project.

  15. From the Debug menu, click Start Without Debugging.

  16. Press any key to close HelloWorld4.

To build and run the Hello World samples from the Command Line

  1. Use the Change Directory command to change to the HelloWorld directory.

  2. Type the following:

    cd HelloWorld1
    csc Hello1.cs
    Hello1
  3. Type the following:

    cd ..\HelloWorld2
    csc Hello2.cs
    Hello2
  4. Type the following:

    cd ..\HelloWorld3
    csc Hello3.cs
    Hello3 A B C D
  5. Type the following:

    cd ..\HelloWorld4
    csc Hello4.cs
    Hello4