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.