First C# projects

Creation of a few simple C# programs

Hello World!

The usual simplest of the simple C# Programs. Following the steps of how to create a New Project for a C# Console Application.

  1. Open Visual Studio
  2. File -> New Project
  3. C# Console Application
  4. Change the name to Hello World, the Solution name will automatically change to match it.
  5. Click OK to create an empty C# application
  6. In order to print “Hello World” to the console, we must use Console.WriteLine(“”);
    Following the WriteLine with a ReadLine will allow us to actual view what was put on the screen by having the program wait for the user to enter something.
  7. Hitting Start or using the Shortcut F5, a Command Prompt will appear with the words Hello World! and will not exit until the user inputs something like hitting enter.
Simple Variables

This next program will just be an example using variables to compute values and display them to the screen.

Creation of a new project for variables example:


In the following code two variables are created, x and y, which are declared as integers. After the variables are declared the x is defined as 3 and y is defined as x’s value plus 7.



Once the code is ran, you can see that the value of y is 10.




There is a special variable type called var that assigns the correct type of variable based upon what you define it as.


As you can see in the following code, the var keyword is used two different variables, one with an intenger and one with a string.

var x = 1;
var y = "Hello World";

The code also displays how a variable that had it’s type declared can have the value defined as soon as it’s declared or later in the code.

int x;
int y = 7;
x = 3 + y;


When the code runs, the output shows the value of y and the two var keyword variables.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s