In this video, I want to actually click on this link that we saw in the last video, and we haven't
clicked on it, but how do we click on it?
Well, if you hover over it, you get an instruction where it says Control Plus.
Click to follow the link.
All right.
So let's just do that.
So it sends us to this website here learn dot Microsoft.com.
And then basically it sends us to the top level statements tutorial.
So here it says C sharp console app template generates top level statements.
Now what is going on here.
So the thing is since dotnet six which has been released a few years ago, Microsoft added the following
to Visual Studio where if you create a console app that you have the option to uncheck this checkbox.
So let me show you which checkbox I mean.
So if you create a new project here and you go to console app and you give it the name, you can select
this checkbox or unselected.
We used unselected the last time which then resulted to this design.
So this is how our Program.cs looks like, even though technically speaking there's a lot more around
it.
But if we now select this, do not use top level statements, then we're going to get this code here.
So there's a lot more going on here.
You see suddenly there is a lot more code.
And the only code that we know is this code here.
So it's the same that we just used in our recent project.
And there is a lot more surrounding it.
But where is all of this code coming from?
Well, the thing is, in the past this has been necessary for you to even start a console application
and run any code and what you could modify at the start and could execute, so to speak, was whatever
is inside of this main.
So in the main method, so to speak, we're going to see what a method is.
I'm not going to go into that for now, but basically you can read through all of this information in
the documentation where it shows you what the code usually looks like.
So all the way to dotnet five and earlier, this was the default console application template.
So the template that was used whenever you created a new project and it automatically populated your
file, your program.cs file with it.
So you can see that we didn't write any of these lines of code, but they were just added to our program.cs
file and now we can use them.
Now there's a lot going on here, and I'm not going to go into too much detail as to what is happening
here, but I still want to give you a very brief overview of what's going on.
So it says namespace Console app for that's just the name of my console app.
And there's this little arrow that I can use in order to collapse it and expand it.
So everything that is inside of these curly brackets here is the body of my namespace.
Where is the content, so to speak, of my namespace console app.
So part of the app that I built.
Then there is this thing called a class.
In this case it's an internal class.
This keyword will only make sense once we know what an external class could be.
So when we are looking at classes in depth and this thing is called program okay.
So let's just accept okay, there is this thing that is called the class.
And in this case it's called program.
And that's also the name of our file by default.
So Program.cs.
And then inside of the body of that class you have something called a static void main method.
Now what is a static void main method.
Well we're going to look at that once we are going to look at methods.
And that will be in chapter five six or something like that.
So don't worry about that too much.
But what I want to make clear that you understand is that the template that we are using is constantly
hiding everything that is up here and everything that is down here from us.
So the only thing that we are using with our new template, so the one where you can see here with the
top level statements here, so where it generates the top level statements for us, it generates this
part here.
This code and the old style was to generate all of this code for us.
But if you look at it this is in here.
And in here is everything that we're going to put into our project.
Let me show you what I mean by this.
So here you see Console.WriteLine.
And then if I go to my recent project to just show you the other styles so to speak.
So here whatever we write inside of here.
So if we just add another line of Console.WriteLine and we add a console dot read key in order to keep
our program running, this will allow our program to keep running once we are executing it.
And we'll see that it says hello world twice now.
So whatever we write here is pretty much the same as if we were writing it inside of these curly brackets.
So inside of here.
Here.
Okay.
So this is the old template.
And here let me just use console red key again.
And I'm going to get the same output.
I'm going to get the same results where it says hello world twice okay.
So the idea really is all of the other stuff is hidden from us, but we don't need to worry about it
because that was introduced by Microsoft in order to just make it easier for beginners to just get started
building your program.
And you don't have to look at this boilerplate code.
What is boilerplate code?
Boilerplate code refers to sections of code that are included in many places with little or no alteration.
So this is just included and we cannot make it any different.
It has to be like this in order for our program to run normally.
All right.
So that's just something that I wanted to quickly show you.
You don't have to worry too much about it, but just now you know that there are these two different
templates and we are going to use this simpler template, which you get by creating a new project,
which we have done, and by selecting the console app, giving it a name and unchecking this checkbox.
And once we do check it, then it will not use the top level statements, which means that this is what
we're going to get if we are not checking the box, we don't get that.
When we're checking the box.
We're getting this boilerplate code.
And by the way, if you want to read this in depth, you can check out the documentation.
But I just think that it is a little confusing because if you look at this, there are so many different
words used that are way beyond what a beginner would understand, and that's why I think it is very
overwhelming.
That's why I would recommend to just keep going with the course, because it's yeah, like these documentations
are way too complex.
It's like reading something in your second language that you're learning at school, but you don't know
20% of the words or 30% of the words, and sometimes the words that you are not understanding are explained
with other words that you don't understand.
So that's the difficult part here that is going on with the documentation.
It can, however, still be very useful at times.
Okay, so that's it for this video.
See you in the next one.