New Digital Era
Back
Back to index...

Hello World

The time has come to write your first program!
Chances are you have already heard of the Hello World program before. It's the ABC of learning a programming language. It's the most basic program that one can do when learnign a new programming language.
Make sure to delete all the default code from the text editor and then write:

using System;

Console.WriteLine("Hello, World!");
Click the green play button on the top menu bar to execute the program. The program will run and a console will open and print "Hello, World!". The text you see below it is information you don't care about for now, you can ignore it.

Did it feel good? My first program ever was also Hello World and it felt amazing when it ran. It was a sort of euphoria.

Let's see what the code means:

using System;
This is telling the compiler that we'll be using functions contained in the "System" library. Note: See the Glossary for definitions of computer jargon.
Console.WriteLine("Hello, World!");
This is calling a function named WriteLine, which is contained inside the class Console. A class is a language construct that groups related functions and data under a name. Again, check the glossary for many definitions.
Don't worry if you don't understand this well yet. Once we get to use it you'll understand it perfectly. In my opinion, at least in programming, practice is better than theory :)

The C# syntax for function calling is as follows: FunctionName + ( + a number of parameters here, separated by commas ',' + ). Additionally, all lines of code in C# must end with ';'. Don't forget this.

The
.
is what's called an operator. There are many operators, like
+
,
-
, etc. Operators are special words to do things. For example, the
.
operator that we just used is called the member access operator. It let's you access what is inside a type, in this case, the Console class. We accesed the
WriteLine
function inside the
Console
class. What this function does is print a string to the console, as you saw. We will be using this function a lot at the beggining.

The
"Hello, World!"
part is what's called a string literal. It's, well, a string. A chunk of text. It must be enclosed in "" to tell the compiler that it is not code, but text.

You may have already noticed that Visual Studio has rich, intelligent text autocomplete. For example, when writing
Console
, the more characters you type, the more concrete the list of things the autocomplete proposes you. You can use the Up/Down arrow keys or the scroll bar to navigate the list of matching suggestions, along with an useful description for most of them. Other IDEs also have autocomplete, but visual studio has the best and most advanced one, at least for the languages that concern us (C# and C++).
Play a bit typing things and you'll see the endless amount of things that C# has.


Next
Back to index...