C Sharp Introduction
C# is pronounced as "C sharp".
Enables
programmers in quickly building solutions
basic structure of a C# program.
xyz.cs
class xyz
{
……..
……..
}
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.

0 comments: