We will start our console application with the popular “Hello World” because that is always the first example in any programming language. Please pardon me; I will like to quickly introduce two keywords in C#. They are;
1.
Console.ReadlLine():
used to feed data into the computer
2.
Console.WriteLine():
used to output result or display text on the screen.
Now let us proceed to
write the simple and common “Hello World” program
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace helloworld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
}
}
}
Waoooooooh, welcome
to your first C# program. I know that a lot of people will be discouraged
because the code is too much. You shouldn’t be. The truth is that if you are
using the latter of visual studio (2005 till date), most of the code is already
written for you. All you need to do is to go to last of { } and add your code.
Some persons may ask,
how can we get to the coding environment of console application of visual C#?
Follow the steps below.
Steps
to enter the coding environment of visual C# console application:
- Click on file
- Point to new
- Click on projects
- Select console application
5. Change the application name (you may
decide to use the default name
6. Click
ok
That is the coding
environment you are looking at.
Start your coding
in-between the last { }, e.g.
static void
Main(string[] args)
{
}
How do I see the
output of my program. Follow the steps below.
How to run console
application:
1.
On the display menu, click on “Build”.
2.
Click “Build helloworld” (the name you
gave to your application). If there is no error in your application, the
application will build successfully.
3.
On the display menu again, click on
“Debug”.
4.
Click on “Start without Debugging”.
You will see a black
window which is referred to as the DOS prompt or DOS window showing “Hello
World”.
We will perform
series of calculations as we move on. But before I continue let me introduce
you to another keyword in C#. As a programmer, you can write plenty of code and
later forget in future what those codes do. To avoid that, you need comment.
Next we talk about comments.
No comments :
Post a Comment