C# HOW TO - HELLO WORLD application




This program, only prints out "Hello World!" to the default output. For C# with a Windows machine, this is the Command Promt.
To get Started:


**********************************************************************

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

namespace ConsoleApplication1 // THE NAMESPACE, NOT THAT IMPORTANT AT THIS TIME LIVE IT AS IS
{
    class Program // CLASS NAME THIS NAME REPRESENTS THE "Program" Object
    {
        static void Main(string[] args) //THIS IS WHERE THE EXECUTION BEGINS
        {
            Console.WriteLine("Hello World!"); //PRINTS THE LINE IN THE CONSOLE
            Console.ReadKey(); //BLOCKS UNTIL YOU PRESS A KEY (FOR DISPLAY PURPOSES)
        }
    }
}

**********************************************************************
  • Open Visual C# Express or Microsoft Visual Studio 2008 or 2010 or whatever version you like.
  • Go to File > New Project > Console Application. (check the bottom for screenshots on how to do this)
  • The Only two lines I added were:
  1. Console.WriteLine("Hello World!"); 
  2. Console.ReadKey(); 
  • The green text is used for giving additional info on why you put a specific line of code, they are called comments. You can write whatever your want after the // as it will be considered as short comments.
    For a multiline comment you can use or //
                                                               //
    or group your comment like this /* your comment here */

Now Press the Start Debugging button to compile and run the application.



File > New Project.


  

Now choose Console Application.



Final Code, generated by Visual C# Express plus the two lines I added.


Program running.

 
Any comments or special requests on how to do anything with in the C# language, I'll be glad to help you if it's in my scope. Thanks and have a nice day.

No comments:

Post a Comment

2 ads