Saturday 9 August 2014

Learn Hello World! program in C#



Hello there


Here i am going to explain C# (sharp) concept in simpler manner.
Anybody can go through and learn very easily.
We will going to use VisualStudio
To create and run a console application

1.Start Visual Studio.
2.On the menu bar, choose File, New, Project.
3.The New Project dialog box opens.
4.Expand Installed, expand Templates, expand Visual C#, and then choose Console Application.



5.In the Name box, specify a name for your project, and then choose the OK button.
6.The new project appears in Solution Explorer.
7.If Program.cs isn't open in the Code Editor, open the shortcut menu for Program.cs in Solution Explorer, and then choose View Code.
7.Replace the contents of Program.cs with the following code.


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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            // A Hello World! program in C#.
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }

    }
}



8.Save the program then build and Run by using F5 or Debog option in VS.

Input and Output:
 If you include the using System; directive at the beginning of the program, you can directly use the System classes and methods without fully qualifying them. For example, you can call Console.WriteLine instead of  
System.Console.WriteLine

using System;


Namespaces:
As I just mentioned above, while discussing using statements, people, including yourself, can create huge piles or collections of code that are all related to each other. To manage these piles of code better, related code is usually put into groups called namespaces. There's a good reason for that particular name, but it is a discussion for another day.
You can see that in your program, just after the using statements, that the next thing is this:
namespace Practice
{ }



Comments: 
The first line contains a comment. The characters // convert the rest of the line to a comment.
// A Hello World! program in C#.


Main Method
A C# console application must contain a Main method, in which control starts and ends. The Main method is where you create objects and execute other methods.
static void Main(string[] args)
 { //... }


Please do correct me if something wrong thanks...

No comments:

Post a Comment