Welcome back.
Before we go on with more on arrays, I want to show you something really, really important in programming.
And that is methods okay.
So let's go ahead and create a new console application.
And I'm going to call this one methods app.
And then let's go and click next I'm going to keep everything as default here.
However we're going to change that very soon because this checkbox here is why we need to look at methods
at this point.
So first of all let's go ahead and create this new project and use that a little later as well.
So there we are.
Nothing new as of this point.
However, I want to show you how methods work.
So generally speaking, when you are using methods, they are always with the same format.
So there we are.
Methods are structured like this.
So you have a modifier.
Then you have the return type.
The method name and rounded brackets.
You have the parameters.
And then you have your code block within curly brackets.
Okay this looks a little complicated.
We're going to build it up step by step because this would be a little too much to handle.
So let's start with a very very simple method.
And I'm going to call this one void my first method.
And then I'm not going to pass any parameters in here.
And then I'm going to have some code in here that I want to be executed whenever this method is being
called.
Okay.
So let's add some code in here Console.WriteLine.
And my first method was called will be executed okay.
So now let's have a console dot write line in here as well.
This is outside of the method.
And then let's have a console dot read key so that our program stays awake okay.
So let's run this and we will see.
This is outside of the method.
But where is this line here where it says Console.WriteLine.
My first method was called.
Well that's because my first method was never called.
And we even didn't look at this void.
We're going to look at that in a second.
So this code here will only be executed if this method is called okay.
So only if we call the method.
And in order to call the method we need to enter the method name.
Then we pass the parameters.
In this case there are no parameters.
And then we use the semicolon.
So this is how we call a method.
Calling a method.
It's the same as executing everything that is inside of that method.
Now let's say we had something complicated in here and not just a Console.WriteLine statement.
So let's say some super complicated code okay.
So now if we call this method everything that is inside of the methods definitions, curly brackets
will be executed.
Okay.
So this here is the definition of a void method that returns nothing.
We're going to see what returning nothing even means okay.
So this is how we call a method.
This is how we define a method.
And now let's run the code again and we will see.
My first method was called some super complicated code.
And then it says this is outside of the method.
So what is going on here.
Well the thing is we're creating something that we can reuse.
So we're creating reusable code.
This method here is easily reusable.
We can just call it as often as we want.
So in order to show that I can just go ahead and call this method again.
And I'm going to call it four times, because each time that I call it, I'm going to run some very
cool code.
And that is exactly the code that I have inside of the curly brackets.
So now what it will do is it will say my first method was called some super complicated code, my first
method was called, and so forth.
So it runs the code four times because I called the method four times and then it says this is outside
of the method.
So pretty much once it ran all of this code, which basically each time runs this code, it ran this
code down here.
Now I could have done this with a loop, but that's not really the point.
It's really just about the idea that you can reuse a method.
So this void, as I said I will cover it later on.
This void just means nothing.
So the void is the nothingness, so to speak.
So what it does is it returns nothing.
So that's the return type.
In order to understand void we need to understand the return type.
And that's what we're going to do in the next video okay.
So.
See you there.