Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Writing Your First Hello World Console Application in C#


In the following text, we will build our first C# Application with, and then without, Visual Studio.Net. We will see how to write, compile, and execute the C# application. Later in the chapter, we will explain the different concepts in the program.



Open Notepad, or any other text editor, and write the following code:



using System;
namespace MyHelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{
Console.WriteLine("Hello World,Welcome to http://www.codesforprogrammers.blogspot.com/ ");
}
}
}



Save this with any file name with the extension ".cs". Example: 'MyFirstApplication.cs' To compile this file, go to command prompt and write:



csc MyFirstApplication.cs


This will compile your program and create an .exe file (MyFirstApplication.exe) in the same directory and will report any errors that may occur.
To run your program, type:


MyFirstApplication


This will print Hello World,Welcome to http://www.codesforprogrammers.blogspot.com/ as a result on your Console screen. So simple, isn't it? Let's do the same procedure with Visual Studio.Net:



With Visual Studio.Net



Start Microsoft Visual Studio.Net and Select File - New - Project; this will show the open file dialog. Select Visual C# Project from Project Type and select Console Application from Template. Write MyHelloWorldApplication in the name text box below and click OK.





Now to compile and execute your application, select Debug - Start Without Debugging or press Ctrl+F5. This will open a new Console Window with Hello World written in it. Once you press any key, the window will close,terminating the program.

http://codesforprogrammers.blogspot.com/feeds/posts/default?alt=rss


This post first appeared on Codes For Programmers(C4P), please read the originial post: here

Share the post

Writing Your First Hello World Console Application in C#

×

Subscribe to Codes For Programmers(c4p)

Get updates delivered right to your inbox!

Thank you for your subscription

×