Latest updates

[5]

C# Introduction

C# is pronounced as "C sharp".

It is a new programming language that    enables programmers in quickly building solutions


basic structure of a C# program.

xyz.cs
class xyz
{
……..
……..
} 

A class is nothing but a collection --- a collection of everything that the programming language contains. It is like a container, which can hold anything. Hence everything in a C# program must be enclosed within a class. We have named our class xyz , you can name accordingly.

In general everything has a beginning and an end. Similarly, a C# program also has a start and an end. 

You can specify the entry point by adding static void Main() to your program, just as we have done below.


class xyz

{

static void Main()
{

}

} 


If we Compile the above code,  the program will run successfully without any errors but shows no output on the  screen. The compiler will generate an exe file.

The words, static and void, will be explained to you a little later,  Main() is nothing but a function. Here we are creating a function called Main. It is followed by the '{' and '}' curly braces. Note that the letter M in Main is capital. The { signifies the start of a function and the } signifies the end of the function.

Now we are going to  add some code in our program.


class xyz
{
static void Main()
{
System.Console.WriteLine("Suhail Osmani")
}
}


Output

Suhail Osmani

Here WriteLine is a function name which exist in Console Class and Console Class inside System Namespace. 

In the next program, we have called WriteLine function twice.


class xyz
{
static void Main()
{
System.Console.WriteLine("Suhail");
System.Console.WriteLine("Osmani");
}
}

Output
Suhail
Osmani

On executing this program, 'Suhail' and 'Osmani' are displayed on two separate lines. Here, we are not required to give anything that has the 'enter' effect, WriteLine automatically prints on a new line each time. Which simply means you can call a function as many times as you like.
C# Introduction C# Introduction Reviewed by Admin on 03:19:00 Rating: 5

No comments:

Sora Templates