Wednesday, October 3, 2012

C# for beginners Part 1

Hello World!


Welcome to your first of all C# for beginners tutorial, in this tutorial you will learn the simple hello world program to start learning C#.

Things you will need:

  1. Microsoft Visual Studio you can download the express edition for free from here free visual studio.
  2. 10 minutes of your time.

Lets start:

Now that you ready to make your first program after installing Microsoft Visual Studio lets open it, now you will have to create a new project there is lots of project's types you can choose from but we will start with the simplest and very basic one of them the Console application.

File>>New>>Project
you will get a window similar to this (it may look different depending on the version of your Visual Studio)

New Project
Project Type

Choose Visual C# for the programming language then Console Application for the program type.
For the name type HelloWorld or whatever you like your program name to be, But in here I will be using HelloWorld as the project name so its a good practice to do the same so that names wont make you confused.

Now that you created the project its time to start writing some codes, This is how your code will look like when you open Program.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
Our program is very simple all we want to do is to make our program say Hello World! and to type anything on the Console window you will have to use Console.Write("whatever you want to type"); or Console.WriteLine("whatever you want to type");

NOTE: The different between both is that Write types what you want then stops at the same line so if you typed anything else it will continue in the same line but WriteLine stops at the new line after what you typed 

NOTE: Console.Write("Hello World! \n"); is the same as Console.WriteLine("Hello World!");
you can read more about \n in escape sequences

Now lets make our program say Hello World! and run it, In the Main type Console.WriteLine("Hello World!");

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

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
                 Console.WriteLine("Hello World!");
        }
    }
}

Now lets Run our program and see what we did press Ctrl+F5 to run your program

Console Result
The Result

Congratulations now you have done your first C# Program you are ready to learn more


NOTE: Click Download below to download sample project. More Download Links

Download From FileFactory!



Hope you enjoyed and benefited from this tutorial please feel free to comment or ask about anything and more tutorials will be added.
Thank you for reading and enjoy your day. 


2 comments:

  1. I like how detailed simple and direct this is good post keep the good work

    ReplyDelete
    Replies
    1. Thank you so much glad you like it


      www.developware.blogspot.com

      Delete