The community is working on translating this tutorial into Ukrainian, but it seems that no one has started the translation process for this article yet. If you can help us, then please click "More info".
If you are fluent in Ukrainian, then please help us - just point to any untranslated element (highlighted with a yellow left border - remember that images should have their titles translated as well!) inside the article and click the translation button to get started. Or have a look at the current translation status for the Ukrainian language.
If you see a translation that you think looks wrong, then please consult the original article to make sure and then use the vote button to let us know about it.
Please help us by translating the following metadata for the article/chapter, if they are not already translated.
If you are not satisfied with the translation of a specific metadata item, you may vote it down - when it reaches a certain negative threshold, it will be removed. Please only submit an altered translation of a metadata item if you have good reasons to do so!
Hello world explained
Now let's start from the beginning:
using is a keyword, highlighted with blue by the editor. The using keyword imports a namespace, and a namespace is a collection of classes. Classes brings us some sort of functionality, and when working with an advanced IDE like Visual Studio, it will usually create parts of the trivial code for us. In this case, it created a class for us, and imported the namespaces which are required or expected to be used commonly. In this case, 5 namespaces are imported for us, each containing lots of useful classes. For instance, we use the Console class, which is a part of the System namespace.
On the other hand, we don't really use the System.Linq namespace yet (for example), so if you're a purist, you may choose to remove this line, but it won't make much of a difference at this point.
As you can see, we even get our own namespace:
The namespace ConsoleApp1 is now the main namespace for this application, and new classes will be a part of it by default. Obviously, you can change this, and create classes in another namespace. In that case, you will have to import this new namespace to use it in your application, with the using statement, like any other namespace.
Next, we define our class. Since C# is truly an Object Oriented language, every line of code that actually does something, is wrapped inside a class. In this case, the class is simply called Program:
We can have more classes, even in the same file. For now, we only need one class. A class can contain several variables, properties and methods, concepts we will go deeper into later on. For now, all you need to know is that our current class only contains one method and nothing else. It's declared like this:
static void Main(string args)
This line is probably the most complicated one in this example, so let's split it up a bit. The first word is static. The static keyword tells us that this method should be accesible without instantiating the class, but more about this in our chapter about classes.
The next keyword is void, and tells us what this method should return. For instance, it could be an integer or a string of text, but in this case, we don't want our method to return anything (C# uses the keyword void to express the concept of nothing).
The next word is Main, which is simply the name of our method. This method is the so-called entry-point of our application, that is, the first piece of code to be executed, and in our example, the only piece to be executed.
Now, after the name of a method, a set of arguments can be specified within a set of parentheses. In our example, our method takes only one argument, called args. The type of the argument is a string, or to be more precise, an array of strings, but more on that later. If you think about it, this makes perfect sense, since Windows applications can always be called with an optional set of arguments. These arguments will be passed as text strings to our main method.
And that's it. You should now have a basic understanding of our first C# application, as well as the basic principles of what makes a console application work.