Ylbtech-microsoft-csharpsamples:ylbtech-languagesamples-hello World |
1.A, example (sample) back to top |
"Hello World" example
This example shows several versions of the Hello World program written in C #.
Safety Instructions |
This code example is provided to illustrate a concept that does not represent the most secure coding practice, so you should not use this code example in an application or Web site. Microsoft assumes no responsibility for incidental or consequential damages arising from the use of this code sample for other purposes. |
To build and run the "Hello World" sample in Visual Studio
Open the solution (HelloWorld.sln).
In Solution Explorer, right-click the HelloWorld1 project and select Set as Startup Project.
On the Debug menu, click Start Without Debugging.
Press any key to close "HelloWorld1".
In Solution Explorer, right-click the HelloWorld2 project and select Set as Startup Project.
On the Debug menu, click Start Without Debugging.
Press any key to close "HelloWorld2".
In Solution Explorer, right-click the HELLOWORLD3 project and select Set as Startup Project.
In Solution Explorer, right-click the HELLOWORLD3 project, and clicking Properties.
Open the Configuration Properties folder and click Debug.
Type "A B C D" in the Command line Arguments property, and then click OK.
On the Debug menu, click Start Without Debugging.
Press any key to close "HelloWorld3".
In Solution Explorer, right-click the HELLOWORLD4 project and select Set as Startup Project.
On the Debug menu, click Start Without Debugging.
Press any key to close "HelloWorld4".
To build and run the Hello World sample from the command line
-
Use the Change Directory command to go to the HelloWorld directory.
-
Type the following command:
CD HELLOWORLD1CSC hello1.cshello1 |
-
Type the following command:
CD. \HELLOWORLD2CSC Hello2.cshello2 |
-
Type the following command:
CD. \HELLOWORLD3CSC Hello3.cshello3 A B C D |
-
Type the following command:
CD. \HELLOWORLD4CSC Hello4.cshello4 |
1.B, sample code back to top |
1.b.1, Hello1.cs
//Copyright (C) Microsoft Corporation. All rights reserved. //This code is published in compliance with//Microsoft Public License (MS-PL,http://opensource.org/licenses/ms-pl.html) of the terms. ////Copyright (C) Microsoft Corporation. All rights reserved. //Hello1.cs Public classhello1{ Public Static voidMain () {System.Console.WriteLine ("Hello, world!."); }}
View Code
1.b.2,
1.B, sample code 2 (sample codes) back to top |
1.b.1, Hello2.cs
//Copyright (C) Microsoft Corporation. All rights reserved. //This code is published in compliance with//Microsoft Public License (MS-PL,http://opensource.org/licenses/ms-pl.html) of the terms. ////Copyright (C) Microsoft Corporation. All rights reserved. //Hello2.csusingSystem; Public classhello2{ Public Static voidMain () {Console.WriteLine ("Hello, world!."); }}
View Code
1.b.2,
1.B, sample code 3 (sample codes) back to top |
1.b.1, Hello3.cs
//Copyright (C) Microsoft Corporation. All rights reserved. //This code is published in compliance with//Microsoft Public License (MS-PL,http://opensource.org/licenses/ms-pl.html) of the terms. ////Copyright (C) Microsoft Corporation. All rights reserved. //Hello3.cs//parameter: A B C DusingSystem; Public classhello3{ Public Static voidMain (string[] args) {Console.WriteLine ("Hello, world!."); Console.WriteLine ("You entered the following {0} command line arguments:", args. Length); for(intI=0; I < args. Length; i++) {Console.WriteLine ("{0}", Args[i]); } }}
View Code
1.b.2,
1.B, sample code 4 (sample codes) back to top |
1.b.1, Hello4.cs
//Copyright (C) Microsoft Corporation. All rights reserved. //This code is published in compliance with//Microsoft Public License (MS-PL,http://opensource.org/licenses/ms-pl.html) of the terms. ////Copyright (C) Microsoft Corporation. All rights reserved. //Hello4.csusingSystem; Public classhello4{ Public Static intMain (string[] args) {Console.WriteLine ("Hello, world!."); return 0; }}
View Code
1.b.2,
1.C, (free Download) back to top |
|
Ylbtech Source: http://ylbtech.cnblogs.com/ This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility. |
Ylbtech-languagesamples-hello World