Export (0) Print
Expand All

Hello World Sample 

Download sample

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

Security noteSecurity 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 open the sample files in Solution Explorer

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory the files will be extracted to, or click Next again.

  4. Make sure the Show extracted files check box is selected, and click Finish.

  5. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the project solution is not trusted. Click OK to continue.

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. 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 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 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. 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 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 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
    

See Also

Community Additions

ADD
Show:
© 2014 Microsoft