Blog Archive

Friday, May 7, 2010

Hello World In C#

.Net is microsoft's revolution about managed code application. Before .Net
java was only language in managed code era.
Like Java vertual Machine (JVM) in Java .Net languages uses CLR (Common Language Runtime).
CLR is interpreter of .Net platform just like JVM in Java.

Microsoft provided many laguages for .Net paltform such as VB.NET J#.NET and C#.NET.

Currently C# is the market leader in .Net technology because it provides greater flexibility for for programmers.
Syntax and coding style of c# is similer to c++ and jave so. It is more esay to adopt this laguage for the programmes which have java or c++ base.

So here is a simple program to print hello world on console window. This small program will help you to understand structure of c# language.

Here is the code:

public class MyFirstDotNetClass
public static void Main()
System.Console.WriteLine("Hello World.");

To compile above example you need microsoft visual studio installed on your system.
You can download express edition on following link:
After installing visual studio or c# express edition you are ready to compile your first c# program.

To Compile Above Program Do Following:
Go to > All Programs > Microsoft Visual Studio OR Visual C# Express> Visual Studio Tools > Visual Studio Command Prompt.

Now a Console window will appear.
1) Type the following command to the console window just opened, and press enter.
edit helloworld.cs

2)Now a dos editor will appear on console window, type above code in editor.
After then save and exit from editor.

3)To compile helloworld.cs just created, type following command, and press enter.
csc helloworld.cs

Following output will appear on screen(Output can vary for different versions of visual studio).

Microsoft (R) Visual C# 2010 Compiler version 4.0.20506.1
Copyright (C) Microsoft Corporation. All rights reserved.

4)To run our program type following and press enter.

following line will print on screen.
Hello World.

1 comment:

  1. Hi error occur in compilation.......

    error CS2001: source file 'helloworld.cs' could not be found falat error CS2008: No Input Specified