This blog will take various topics of C# programming and provide easy examples for understanding the concepts.

Saturday, December 30, 2006

As with any other programming languages, let us start with a simple program called a "hello world". This program will just display a line "Hello World" , but in the process, we plan to learn:

1) How to write a basic C# progam

2) Sections of a c# program

2) How to compile a basic c# program

using System;

public class HelloWorld

{

static void Main(string[] args)

{

Console.WriteLine("Hello World! How are you");

}

}

Typing /Editing your first program:

Open your favourite text editor, which can be "notepad" or "editplus" or any other text editor

you prefer and type out the above program.

Save the program as "HelloWorld.cs"

Compiling your first program:

Open the visual studio command prompt

Type the C# Compiler by calling : csc

Pass the C# Compiler the name of your program : in this case HelloWorld.cs

Press enter.

If you have not made any syntax errors, the program will compile and you should see

the following in the command window

Your first program will be compiled into an exe file, run a dir command if there is an exe file in the directory:

As you see, the directory contains an exe file : HelloWorld.exe

Run the exe file by typing : HelloWorld.exe and press enter

There you are !!!. Your first C# program has run successfully and you see the output "Hello World" in the console.

0 comments:

About Me