Introductions to C#


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.

Up Next
    Ebook Download
    View all
    Learn
    View all