SIGN UP MEMBER LOGIN:    
ARTICLE

Introductions to C#

Posted by Mahesh Chand Articles | C# Language January 02, 2002
C# is a new programming language developed by Microsoft. C# has power of C++ since it's derived from C and C++. It is simpler as VB.
Reader Level:

This part of tutorial explains about C# and how to write and compile your first C# program from command line.

What is C#?

C# is a new programming language developed by Microsoft. C# has power of C++ since it's derived from C and C++. It is simpler as VB. Besides that, C# is a Java like language for web programming and it has some good features of Delphi too. Microsoft says, that C# is the best language to develop its .NET Framework applications.

Installing .NET SDK

Installing .NET SDK is first step to run C# on your machine. You can install .NET SDK on Windows ME, Windows NT, or Windows 2000. But Windows 2000 is recommended. After selecting your OS, you need to follow these steps:

  • Install IE 5.5
  • Install Microsoft .NET Framework SDK. It's free and you can download it here. NET Framework SDK.
  • After installing these you can write your code in any text editor and save it as .cs extension. Type this in an notepad and save as my.cs.

C# Compiler and Editors

.NET SDK Beta 1 release of Microsoft's new platform, .NET, incorporated with C# command line compiler. You must have to install .NET SDK to run a C# program. Once you install .NET SDK, you can write your C# program in any text editor including notepad, wordpad or Visual Studio. There are some third party editors are available in the market too. Some of them are free. Check out tools section of C# Corner.

Write your first C# program

Writing your first C# program is similar to writing C++ applications. You open any text editor, I described in the above paragraph and type this code.

using System;
class MyClass
{
static void Main()
{
Console.WriteLine("Hello World!");
}

 
Compile your first C# program

Now use command line to compile your cs file. C# compiler takes at least one argument i.e., file name. Say your C# file name is myclass.cs then here is command line syntax.

csc myclass.cs 

C# compiler creates an exe file in the bin dir of your project. Just run this exe and see the output. 

Now, lets take a look of your code line by line. The first line of your program is using System.

using System

Why using System? System is a namespace which stores system classes. The Console class, I used in the program to display the output on the console is defined in the System namespace. That's why this like is there.

Next line is class MyClass. The class keyword in C# is used to create a new class.

class MyClass
{
....
}

Each class has one static void Main() function. This function is the entry point of a C# program.

static void Main()
{
Console.WriteLine("Hello, C# World!");
}

The WriteLine method of the Console class writes text to the console.

Login to add your contents and source code to this article
share this article :
post comment
 

Hai Mahesh, Good work.. congrats. It helped me as Im a beginner in C# Thanks a lot. Joby John jobyjc@gmail.com

Posted by Joby John Jun 26, 2007
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor