Console vs Windows vs Web Application
The .NET framework, combined with C#, allows you to develop several types of software. These include Windows-based programs, web-based applications and even console applications for execution from the command prompt. In this article, we will create a console application similar to the original Hello World program. A console application requires little supporting code and gives the clearest opportunity for understanding the language.
Creating the Program
Step 1 - Create a Console Application
I will assume that you are using Microsoft Visual Studio or Microsoft C# Express Edition to develop the program. Launch your chosen development environment and create a new project of the type, "Console Application". Name the application, "HelloWorld".
Step 2 - Add the Functionality
The development environment should have created all of the template code needed for a console application. This includes a "Main" function that is similar though not identical to the original K&R application. All that is left is for you to do is to add the code that actually prints "hello, world".
C# is derived from C but does not share all of its commands. We cannot use the printf command to output text, as this command is not supported. Instead we use the Console.WriteLine function. Add the following code between the braces {} of the Main function, ending the second line with a semicolon (;).
Step 3 - Test the Program
You can execute your program directly from Visual Studio or C# Express Edition by selecting "Start Without Debugging" from the Debug menu or by hitting Ctrl-F5. You should see the words, "Hello World" in a console window and an instruction to press a key to continue.
Note: You would usually start programs with debugging enabled by pressing F5. In the case of a console application, the application may close before the results are seen. Using Ctrl-F5 adds the requirement to press a key when the application stops.
No comments:
Post a Comment