Hello World
� Every time you learn a new programming language you will always start with a Hello World program and C# is no exception. � First of all start up C# and create a new project, name it Hello World and select Console Application. � What you should now see is something similar to this: � using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Hello_World { class Program { static void Main(string[] args) { } } } � The only thing we will be editing will be within the curly brace after this line: � � static void Main(string[] args) � This is the main function of the program and whenever you open the application the contents of this will be run. � To make our program all we need to do is add the following line between the curly braces: � Console.WriteLine("Hello World"); Console.ReadLine(); � � Now to explain what is happening. The Console part specifies that what you are going to do will involve the console. The WriteLine part specifies that you are going Write a Line to the screen. Now what is inside the parenthesis is what will be output to the screen. We place it within "" to specify that it is not a variable. � � Now this part is important, at the end of every statement you must remember to add a semi-colon(;). This tells the compiler that everything after this is a different command. � � The next line just pauses the screen until you press a key. If we didn't do this and you ran your code the screen would close instantly and you wouldn't see the results. � So now if we run our code we should see: Hello World! appear on the screen. Well dome you have written your first C# program. � It may look like nothing but I assure you that many of the people who program well know applications like Word and Firefox and World of Warcraft started off writing the same program as you but in another language. � Next up we will be learning about variables and how to assign them and output them. �
|