C-SHARP - 1.4 My first program(2/2)

We now meet again for the continuation of our video "My first program". So you see this interface that appears on the screen Indeed, it does a lot of things. But don't worry, I'll explain everything to you in detail. On the right, we have a list of files, We have a Program.CS file. CS which means C#. Automatically when we create a new project he created a file for us. CS. And he added us the default code that I will explain to you right after. You see that we have a solution as I told you earlier the difference between solution and project is that the solution is a kind of box that brings together several projects. Here we have a solution called ProjectCS and inside we have a project that is also called ProjectCS. We could very well right-click on the solution and add a new project for example if it is as part of creating a game on iOS and Android. But for now we don't need it, We're just going to develop with this first project. Then, this first program.CS file, You see that we have a dependency tab Here Frameworks And Microsoft DotNetCore App Which tells us what our program depends on so that it works properly So we rely on this code library that will allow us to do certain things and in particular here to call this Console function.WriteLine() How will it go concretely? It is here in this window that we will write our code then we will click on the play button to run our program and finally we will have an exit window that will appear on the screen. You see that if I click on the play button on a Hello World which appears In our program we have this line Console.Writeline ("Hello World"); Console.WriteLine() is what is called a function. It will allow you to display things on the screen that are passed to it as a parameter In particular, here we display the characters we pass here in quotation marks. That's why when we launched the program, In the exit window is displayed Hello World. However, you see that I have additional things here he tells me "out of" and there he puts all the way to ProjetCS.exe Which is the program we built just now by pressing the play button. It was an executable who told me that Hello World is the release of this program, that is, the result of the program. So don't worry about these additional lines, they are normal. You can now close the terminal. I'll explain in more detail how this code works: you may be wondering why we have all this? Here the code that will interest us is really that line. In fact, all he has there is just to define what we call an entry point, that is, a place where we will be able to start executing our code and we what interests us the most, That's that part in particular. You see that in C# we have braces Allowing to define a block of code, i.e. we will open a block of code For example, then inside we will write things and we end up closing the block of code with the last brace Here "static void Main()" is the default entry point in general in programming languages You have this Main function. No matter which programming language it is Java C++ Python etc. you will find this point to enter Main. On the other hand, all this part for us is not very important, Here what is important is really the code we are going to type between these braces. This is where we are going to write our program so we will start modifying it and play with this Console.WriteLine() function. You see, for example, if I take this line and copy and paste. That I restart the program and well this time I have Hello Word which is displayed twice I have these 2 lines that appear on my exit window. Several remarks, in C#, As I told you, what is important is the hugs This is what will allow us to define our block of code. Inside these braces in quotation marks I do what I want. I don't need to respect tabs as is the case in different languages such as Python for example. But on the other hand in C# I can very well go back to the line and it works. My program will run and we will have the same result. I can even put the 2 lines one after the other because you see this line, It is called an instruction and in C# At the end of an instruction, well we have one; So he knows that this is an instruction to execute and then he has another to do. If I restart and well I would also have the same thing. And on our output window I do have a return to the line between each instruction because the Line of the Console.WriteLine() function Is a return to the line if I remove it and restart the program. I'm going to do it You see that the lines follow each other directly. There is no longer this return to the line. Small precision, how you will arrange your code Of which you call a function will not affect the result of the output window. What will have an impact is either change the function as we have just done Or to give different content to this function For example, if I say Hello in the first, and put everyone in the second, I'm going to put the Line back to the line I'm relaunching Well, the program displays "Hello",Then "Everyone". You see that it only works for reasons of readability, well We structure the code line after line. And tabs are used so that the code is simply easier to read. The day you are going to be a company or you are going to do a group project, your code must be easy to read For other developers, otherwise it's very restrictive. But remember that it has no impact. However, if now I give him code that is not valid: How will it go? For example, let's say that if I forget to put it; This is where you will see that when you write code you must be very rigorous because the code is very precise. You see that here if I forget to put it; And that I launch the program and well it doesn't work. I don't have an exit window, I don't have a result and I have an error. You see an error that tells me "; expected." When you have a mistake don't panic, you always have to look at where the problem comes from. This block here is very important because it informs us at which line the error is Whenever you have errors, this is where they will appear And here we see that the error is on line 9 exactly. And you can in particular click on the error and automatically it will go to the line where the error is. So he tells me that on line 9 Well, there is one; who is expected. And it's going to be the same for any other mistakes you might make. For example, if I forget to put a hug, Here I deliberately make a mistake. I deliberately make a mistake. I deliberately make a mistake. And he says that from line 7, There's a problem and that's what should alert you And to see indeed at yours I forgot a hug so you correct the error and at that moment you can click on play and there it works again. I tell you that but often program errors are due to small errors like this Even senior developers make these kinds of mistakes That's why you have to get used now to not forgetting brace commas etc. So here it is in this video, we saw together how to create our first program and thus run it to achieve its result. In any case, I hope you liked this video! I'll see you next time in a new video!