Welcome back.
In this video we're going to look at the other template that there is.
So what do I mean with this.
Therefore let's go ahead and create a new project.
Because we have not used the default project of the past.
So I'm going to call this one old style.
And therefore let's go to next.
And here use do not use top level statements.
So if you hover over it you will see whether to generate an explicit program, class and main method
instead of top level statements.
We were using top level statements all the time, and that is because that is just making it a lot easier
for you to directly jump into the code and not have all of this overhead of code.
Now, not using top level statements is something that has come in just recently with dotnet six.
Not super recently, but just a few years ago.
And many of the videos that are recorded in the past that are still great videos, and I'm really happy
about them.
Students love them.
They were recorded with Net five and those were not using top level statements.
What does that mean?
Well, that means that a program looked like this.
Okay, so instead of just having this console write line statement, a program looked exactly like what
you can see here.
So let's look over this entire piece here before going to the next videos.
Because there I want you to be able to understand what's going on here and basically apply all your
knowledge just to this other style.
There's not really too much crazy stuff going on, but still, there are a few keywords that you need
to understand.
So first of all, we have this namespace keyword and a namespace in C, sharp is used to organize code,
and is primarily a way to bundle related classes or other types under a unique name.
Think of it as a folder on your computer that helps you organize files here.
Old style is the name of the namespace.
All code that is part of this namespace will be enclosed within curly brackets.
So that's what you can see here.
Then we have this internal class program.
Program is just the name of our class.
There's a lot more to talk about about classes than I can just do in this quick overview.
But still, this is just the name of our file Program.cs file.
And we have this class keyword here, which is a keyword that tells C sharp that you are defining a
class.
And a class is like a blueprint from which objects are created.
It can hold data and methods to operate on that data.
So there is one method in here already, and we can create more methods inside of this class.
But more on that later.
Then you have this internal keyword, and this is an access modifier that specifies that this class
is accessible only within the same assembly.
Think of an assembly as a collection of code and data in a single unit, like a package.
It's not accessible from other assemblies, so that just means that this class program will only be
available to other classes inside of our old style namespace.
We're going to learn more about that and which other keywords there are other than the internal keyword
here, but just accept it at this point.
Later on, it will make a lot more sense.
There are still a few other keywords that I want to talk about, but however, what you can see is we
create this class called program and then within curly brackets, that's the content of the program
class.
So everything that is inside of those curly brackets is part of our program.
Okay.
So inside of this program you see that we have this one thing called static void main.
Now you have heard void before.
And void is the return type that returns nothing.
Right.
We've seen that before.
And this is a method.
So this method is called main.
And you can see within brackets it accepts parameters.
Now it says that it wants to have a string array called arcs.
So it just means that you can pass arguments to your main method before it does its thing.
That's also something that you don't fully need to understand at this point of the course.
We're going to cover what that exactly means later on.
However, there's this one keyword static.
And static means that this method belongs to the class itself and not to any instance of the class.
So you don't need to create an object of the class to use this method.
You can call it directly on the class.
So what is this?
This just means that we can run this main method without having to manually call it, and without having
to create an object of our class program.
So it just makes it a lot easier for us to just get started for now.
Except that when you are using this template that you will have this internal and static keyword, they
will make a lot more sense once we actually understand object oriented programming.
And this is just how.
The structure of the old school template is.
But whenever you are using this old school template, it gives you a lot more flexibility and freedom
as well.
Now the thing is, we have this thing called here.
Console.WriteLine.
Hello world.
Now this line is something we have seen before and that's quite easy.
So basically all the code that we executed in the past was within those curly brackets.
By the way the main method is just the entry point into our software.
This just means that whenever we click on the run button, the main method here will be executed.
It's the starting point.
It has a very special name.
It's called main.
This is a very special name for a method, which is why it is treated differently.
So it's really when you start running your application, it's going to search for the main method,
and then it will execute whatever is inside of the main method.
So if you have code that is outside of the main method, but never is called inside of the main method,
it will not be executed.
Let me show you what I mean.
So if I now copy this code and I paste it out here, you can see I get an error.
It says the name Writeline does not exist in the current context, so it will not be executed.
It will not do anything.
So it needs to be inside of the main method, or it needs to be called from the main method, or it
needs to be called from something that is called from the main method.
We're going to look into that a little later, but for now, let's look deeper as to what this main
method actually does for us.
But again, it is the starting point of our application.
So if we take any of our other projects, all the code that we had in here and there was basically just
where this entire code.
So let me get rid of this line.
This entire code was hidden from us and we were here.
So you are here like on maps, right?
So all of the projects that we were building in the last few examples, they were all inside of here.
Let me show you what this means.
So I have two projects now.
This is the old school old style project so to speak, with the top level statements.
And this is the one without top level statements, our methods app.
Okay.
So this methods app has all of this code these variables and these methods.
It has all of those are basically let me cut this whole stuff out and put it in here.
It's the same thing.
So now that's the code from our last lecture, the one about methods and parameters and return types
okay.
And it is the same thing now but we just see the other stuff.
Before we didn't see that we were inside of a valley, but we were all the time doing our stuff inside
of a valley.
But we didn't know that outside of that valley that there were a bunch of mountains and that there were
a bunch of other things around us, the whole world, so to speak.
And we were just in this valley doing our thing, and we were safe in that valley, and it was easy.
But now we're getting out of that valley and we're seeing, oh, there's actually more to it.
And that's a very simplistic example of what's going on.
But yeah, basically now whenever we are using our code, instead of using it, the style that we used
before where we didn't have the top level statements, we now just have the top level statements, but
our entire code will go into the main method.
So we have this method called main.
And inside of it all of our code will go.
Now you can collapse it.
You can see then it gets smaller.
But yeah basically that is it.
So nothing changes.
The only thing that's different is that now our code will be inside of the main method and we just work
from there.
Okay.
So that's it for this video.
See you in the next one.