So in the last video, we really modified our code drastically.
We used the old style slash, the top level statements template.
So what you can see here is that we have all of these additional pieces of code.
However, what we did is we just pasted methods directly into another method.
So there is this method called main.
And we just put our other methods inside of it.
While this is fine, it is not good practice.
So it's good if you take your definition and separate it.
It can still be in the class, but it should not be inside of the other method.
So let me take that out here and put it in here.
So add two values.
I want it to be outside of my main method, but suddenly I get an error.
Why does it not accept my add two values even though it's the same method?
Well, that is because I need to add the static keyword here.
So the static keyword I set it earlier.
It is a little tricky, but what it does is it allows us to define this method and use the method without
having to create an object of the program CSS file.
Let me quickly show you how that would look like.
Even though you don't need to memorize any of that, you don't need to fully understand what it is.
So I'm going to say program my program equals new program.
And then I can just say dot my program, dot add to values.
And suddenly my code is fine.
Suddenly, suddenly I don't have this problem I wrote disappears.
That is because what I now did is I created an instance of my program class, and now I can call the
methods that are part of that program class.
So we have this class internal program class.
And now I'm using the method that is defined inside of that class that is outside of the main method.
And I can use it.
So that's what this whole thing is about like the static being there.
Because if I don't have the static, I need to create an object of that class.
If I use the static, I don't have to do it.
So that's a very simplistic explanation.
That's why I'm going to get rid of this again.
I just wanted to quickly show this to you, and we are going to cover this in a lot of depth in the
next few chapters, but we're going to look into object oriented programming in a lot of detail.
But for now, this is good enough.
So now you know how to get your method that we defined to be outside of the main method.
And that is better practice, right?
So let me do the same thing with subtract two values.
And now I'm going to make that method static as well so that I can actually use it inside of my main
methods code block.
So that just means that from a let's say workflow perspective, what happens is the main method is the
starting point of our application.
So our app starts running, it searches for the main method, and then it starts running the code from
the main method.
So it creates this variable int result.
Then it writes this Console.WriteLine statement that creates another variable.
It goes through this piece, and then it uses a method that is defined outside of the main method,
which is this.
Add two values okay.
And that's what the better approach here would be when we are creating methods.
So from now on we're going to pretty much mainly use the top level statements template, because it
just gives us a lot more understanding as to what is going on around us, because before that, we just
really needed to understand how to walk and now we can start running.
Okay.
So yeah, that's it for this video.
Again, this will make a lot more sense once we get used to it when we use it a lot more.
So don't worry about it.
At this point, it's really just a slightly different template that we're using and it will get a lot
easier over time.
So see you in the next video.