Hello, this is my first article instructing how to program in C sharp. This article will show you how to create your first program in C#. To start simply open up notepad or any other text editor. You can also use a program such as Visual Studio 2008 to create your program. In the next tutorials I make I will be only writing the code for the specific thing I am writing the tutorial for, and not the whole program. It is your responsibility to fill in the necessary code in order to make the program run.
The first thing we have to do is create a class, which we will call Hello.
class Hello
{
}
Now we have to put the Main method in the Hello class (Don’t forget the brackets!)
class Hello
{
public static void Main()
{
}
}
Now lets go ahead and put in the code that will write “Hello World” in the console.
Make sure to include all the necessary small details like quotation marks and semi-colons. Any small mistake will make it so your program will not run.
class Hello
{
public static void Main()
{
System.Console.WriteLine(“Hello World!”);
//Putting two slashes before a line is known as commenting, and the compiler will ignore these
// lines. It is always good to comment your code to make sure other’s reading it will understand you.
}
}
Now save the file as Hello.cs (make sure the extension is .cs) and use your favorite c# compiler (A quick Google search will find one) in order to create an application that you can run. Once you have created the application go ahead and run it and see what your program does!