Udostępnij za pośrednictwem


Hello World Sample

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

To get samples and instructions for installing them

  • Do one or more of the following:

    • On the Help menu, click Samples.

      The Readme displays information about samples.

    • Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.

    • Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.

For more information, see Visual Studio Samples.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

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 then click Set as StartUp Project.

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

  4. Press any key to close HelloWorld1.

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

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

  7. Press any key to close HelloWorld2.

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

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

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

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

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

  13. Press any key to close HelloWorld3.

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

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

  16. Press any key to close HelloWorld4.

To build and run the Hello World samples from a command prompt

  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
    

See Also

Concepts

Visual C# Samples

C# Programming Guide

Reference

Hello World -- Your First Program (C# Programming Guide)