C# - Hello World
In this tutorial you will learn how to make applications using C#2010.
For this tutorial we will make a simple hello world application, that will show a messagebox when clicking a button.
Start by creating a new project. You do this by clicking the Create a new project button in visual C# or visual Studio 2010.
There are 2 ways for doing this:
A new window should pop up.
1.Select a C# Application.
2. Select a Windows forms application.
3. Give it a nice name ( hello world )
4. Press OK.
When you clicked OK, Visual C# should be busy making a standard layout for your application. When it's finished loading, your screen should look like this:
What you need to do now, is double click on the button icon in the toolbox (at the menu on your right):
Visual C# should have placed a button on your form, and your form should look like this:
You can drag the button to any location on your form using your mouse. You can also resize the button to make it larger, or smaller.
Now , we're going to change the text of the button from button1 to Press me !
To do this, click once on your button and change the Text property in the properties window:
Press enter, and your button should now look like this:
We now have our basic layout. It's time for writing the code behind the button. To do this, Double click on your button on your form.
A new tab should open up:
What we need to do now, is writing our code between the
{
//(Code goes here)
}
signs of private void button1_Click(object sender, EventArgs e).
Write the following code between those signs:
Messagebox.Show("Hello World");
The text between the quote signs is the text that will be displayed in the messagebox. Do not remove the quote signs for they are required !
Your code should now look like this:
The ; is required at the end of every line of code. It tells visual C# when the code stops on a specific line.
To run your application you can press F5 or you can click the green arrow button in visual C#. This is called debugging.
Your form should now open on your screen:
Click the button and you should see this:
Congratulations ! You made your fist hello world application !
You can find your exe file by building your application first. You can do this by clicking the build button in Visual C#2010:
RIght now, your application has been built and can be found here:
C:\Users\You\Documents\Visual Studio 2010\Projects\Hello world\Hello world\bin\Debug\hello world.exe
That's it for this tutorial. If you have any more questions, please leave them in the comment section below.
Have a nice day !
Download the source codes:
Hello world.rar (34,7 kB)