void Method1()
{
int myVariable = 0;
}
void Method2()
{
// here we will get an error:
//The name 'myVariable' does not exist in the current context
myVariable = 1;
}
At the code above, we can't access the 'myVariable' variable from Method2, because it isn't in the current context (scope), in order to access this variable inside two methods we have to declare it at the same level as our methods (for example declaring above Method1), you can read more about scopes here.A small summary:
- Declarations
- Classes
- Variables
- Properties
- Methods
- Functions
- Modifiers
- Scopes
What's next?
I'm sorry about my short time, for next post I'll try to cover 'Inheritance and Implementation' inside classes to make it more OOP, Feel free for comment and share content or ask questions.