Author: Kristofer Gäfvert
First Published: April 3, 2004
Last Updated: January 15, 2005
Last Reviewed: January 15, 2005
PDF: N/A
Download Code: CSharpFirstApplication-Code.zip
Table of Contents
Introduction
Your first application
HelloWorld
It is not working!
The code
This article will help you to write your very first application in C# (pronounced ‘see-sharp’). To follow this article you will need a text editor. Good old notepad will work, but I recommend a text editor with at least syntax highlighting and auto indent. These two features will make coding much more fun. For small application such as those I will present in this article, I use NotePad++. It is a great, small text editor.
No, you do not need Visual Studio .NET to write .NET Applications. Many people think so, but this is not true. An IDE (Integrated Development Environment) will help you to write code in the future, but when learning how to program, I usually recommend a simple text editor.
Good luck, and now, let’s get started!
In this chapter you will write your first application. I will also give you some basic troubleshooting guidelines, if your application do not compile correctly.
It would probably be a good idea to start with a simple “Hello World”-application (couldn’t resist to start with the classic one).
using System;
namespace HelloWorldApplication
{
/* The Hello World class */
class HelloWorld
{
static void Main(string[] args)
{
//Write "Hello World" to the screen
Console.WriteLine("Hello World!");
}
}
}
Save this code as HelloWorld.cs (if you are using NotePad, make sure that you do not get the extension cs.txt). After you have saved the file, open a command prompt (Start->Run, type “cmd”). Go to the folder that you saved the file to, and write:
csc HelloWorld.cs
If you are lucky, you will get this screen:

This one tells you that your code compiled, and that you are ready to run the application. To run the application, type:
HelloWorld.exe
If everything went as expected, it should now write “Hello World!” on the screen.