How to Write a “Hello World” App in C#

What are T-SQL Snippets in SSMS? Article on TechHowTos.com

Visual Studio is an extremely powerful IDE for building many types of applications.

In this how-to, we are going to build a “Hello World” Windows forms application in C#.

If you don’t already have Visual Studio, the you can download Visual Studio Community Edition which is free.

Ok, let’s build our Hello World app!

In this example I’m using Visual Studio 2013 and .NET Framework 4.5 but the philosophy is the same for newer versions of Visual Studio and .NET Framework.

So, after launching Visual Studio, we click on “File“, “New“, “Project“.

image

We then select the template for this new project, in this case “Windows Desktop” (1), the version of .NET Framework to be used (2), the type of the project, in this case “Windows Forms Application” (3), the name and disk location of the project (4 and 5), and finally the solution name (6) which by default gets the same name as the project name but of course you can change it if you want. After all these are set, we click on the “OK” button.

image

Right after we click OK, the new project is ready for development. The below screenshot illustrates the development environment for this Windows Forms project.

The next step is to drag and drop a “button” control from the toolbox right onto our form (named Form1 – you can change the name in the Properties dialog on the lower right section of the IDE).

image

Right after we add the button, we set the two below properties in the Properties dialog which can be found on the lower right section of the IDE):

  • Name: btnClickMe
  • Text: Click Me!

Now we need to set the button’s behavior when clicked. We double-click on the button control on the form and an “event handler” for the mouse click event on the button is automatically created. Now all is left is to add to the event handler the code we want to be executed when the button is clicked. To this end, we add the code: MessageBox.Show(“Hello World! This is a C# program!”);

image

Right after adding the code, we press F5 or click on the Start button (has the “play” sign) and if everything is OK, our program runs.

image

So let’s test our program by clicking on the “Click Me!” button:

image

That’s it! As you can see, when we click the button a popup (message box) is presented displaying the “Hello World” message!

Reference: TechHowTos.com (http://www.techhowtos.com)

Recommended eBooks on SQL Server:

Tuning SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Tuning SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Administering SQL Server: eBook by SQL Server MVP Artemakis Artemiou
Administering SQL Server: eBook by SQL Server MVP Artemakis Artemiou

 

 

 

 

 

 

 

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 5.00 out of 5)

Loading...

Share this!
Avatar
About Artemakis Artemiou 33 Articles
Artemakis Artemiou is a Senior SQL Server and Software Architect, Author, and a former Microsoft Data Platform MVP (2009-2018). He has over 15 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and TechHowTos.com. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Artemakis's official website can be found at aartemiou.com.