Welcome back.
In this video I want to talk about scope a little bit more because we've seen scope before.
I think it was an if statement where we created a variable inside of an if statement, and we couldn't
access that variable outside of that if statement.
Now it's going to be the same thing for our add to values.
So we saw that a little bit.
So let's say I wanted to use the result.
You see I have this my result variable that automatically is being used the one that I defined down
here.
But I cannot just use this result variable that I created inside of this method.
So I cannot use result and then is equal to zero or whatever.
Okay.
That doesn't work because this result variable is only visible inside of the add two values method.
So I could have another method int and this one would be subtract two values.
And now I could have the same design.
So now I could say also int result is going to be value one minus value two.
And then I can just return result.
Now this result here is a very different result than this one here.
So it is its own result.
So that's why I can't just use int result.
Because usually if you have defined a variable here at the top let's say int my result, you can use
that my result variable throughout your entire rest of the file inside of the same file.
So I can use it down here I can just use int result.
But I can also store the result here like so.
So I can get that result and store it inside of my program.cs level integer variable because we are
inside of the program.cs file, right?
But then I can also use it here, I can just use my result is equal to result, and then I can use my
result down here to override it with whatever this result will be.
Okay.
So the idea here really is that you can create a variable that you can access throughout your entire
file, but then you mustn't forget that there are also variables that don't have that same scope.
So for example, any variable that we create inside of a method is only available in the method as we
saw.
Then this parameter variable is only available inside of the method itself as well.
So only in here can I use value one and outside I cannot use value one.
I cannot just set it to five or something like that.
I can only use value one inside of the method where I defined it.
All right.
So I'd say this is good enough for now.
We're going to cover scope a little more again once we need it.
Once we get a bigger scope in general for our application, because currently, technically speaking,
everything that we're doing is inside of our main method and we haven't even understood what the main
method is, and that's what we're going to cover soon.
So see you in the next video.