Introduction Of C#

C# is a general purpose, modern and object – oriented programming Language Pronounced as “C sharp”.It was developed by Microsoft within the .NET initiative led by Anders Hejlsberg.

The following reasons make C# a widely used professional language –

  • It is a modern, general – purpose programming language
  • It is object oriented.
  • It is component oriented.
  • It is easy to learn.
  • It is a part of .Net Framework.
The .Net Framework

The .Net Framework is a revolutionary platform that helps you to write the following types of applications –

  • Windows applications
  • Web applications
  • Web services

The .Net framework applications are multi- platform applications.The framework has been designed in such a way that it can be used from any of the following languages: C#, C++, Visual Basic, Jscript, COBOL , etc. All these languages can access the framework as well as communicate with each other.

C# Program Structure

C# Program Structure so that we can take it as a reference in upcoming chapters.

Creating Hello World Program

A C# program consists of the following parts –

  • Namespace declaration
  • A class
  • Class methods
  • Class attributes
  • A main methods
  • Statements and Expressions
  • Comments

Let us look at a simple code that prints the words “Hello World ” –

using system;

Namespace HelloWorldApplication

{

class HelloWorld

{

static void main(string [] args)

{

/* My first program in C# */

Console.WriteLine(“Hello world”);

Console.Readkey();

}

}

}

Look at the various part of the given program –

  • The first line of the program using system ;- The using keyword is used to include the system namespace in the program. A program generally has multiple using statements.
  • The next Line has the namespace declaration. A namespace is a collection of classes . The HelloWorldApplication namespace contains the class Helloworld.
  • The next line has a class declaration, the class Helloworld contains the data and method definitions that your program uses. Classes generally contain multiple methods define the behavior of the class.However , the Helloworld class has only one method Main.
  • The next line defines the main method, which is the entry point for all C# programs. The Main method states what the class does when executed.
  • The next line /*……*/ is ignored by the compiler and it is put to add comments in the program.
  • The Main method specifies its behavior with the statement Console.WriteLine(“Hello World”). This statement causes the message “Hello world!” to be displayed on the screen.
  • The last line Console.ReadKey(); is for the VS.NET users. This makes the program wait for a key press and it prevents the screen from running and closing quickly when the program is launched from Visual Studio.NET.

Leave a Reply

Your email address will not be published. Required fields are marked *