Home > Tutorial for Beginners > C# and .NET Programming Tutorial for Beginners

C# and .NET Programming Tutorial for Beginners

C# and .NET Programming Tutorial for Beginners – Understanding the Hello World Program.

Just you need to insert the following line of code into the outline program in the code window in Visual Studio/VSTS:


using System;
using System.Collections.Generic;
using System.Text;

namespace MyFirstHelloWorldApp
{
  class App
  {
    static void Main(string[] args)
    {

 
// every console app starts with Main

System.Console.WriteLine("Hello, world!");
}
}

The above code looks small but it will help you in understanding the basics of C# (CSharp Language)

Now let’s examine the code and see how it works:

1. The below lines are part of .Net Framework that you will be using:


using System;
using System.Collections.Generic;
using System.Text;

2. Next line specify that you are creating a class called App inside a namespace called MyFirstHelloWorldApp.


namespace MyFirstHelloWorldApp
{
  class App

Note that class is a container for your code. You must have at least one class in a program, but most programs have several. Classes are a fundamental part of programming in C#,

A namespace is a way of grouping several classes together. The full name of the Program class is actually MyFirstHelloWorldApp.Program, because it’s inside the MyFirstHelloWorldApp namespace.

3. The next line declares a method called Main. Methods are very important in C# – they are blocks of code that do most of the work in a program. A class can have multiple methods – you can think of methods as actions that your class can perform.


namespace MyFirstHelloWorldApp
{
  class App
  {
    static void Main(string[] args)
    {

 

As mentioned in the main code – // every console app starts with Main.

4. Now the Last line of the code – This last line actually writes the message to the screen.


System.Console.WriteLine("Hello, world!");
    }
  }

System.Console is part of the .NET Framework. Inside the System.Console class there is a method called WriteLine, which writes a message to the console.

Instead of System.Console.WriteLine, you can also use Console.WriteLine. This is because you are already defining using System in the first line of the code.

Note that - The C# language ignores line breaks, so you need to add a semi-colon to show the end of each statement.

References – http://msdn.microsoft.com/en-us/library/orm-9780596521066-01-01.aspx

Post Comments Below

  1. Ali raza
    April 25th, 2011 at 18:07 | #1

    Nice !!!

  1. No trackbacks yet.