The most basic form of scope is a block of code with it's own variables that can't be accessed outside of it like so:
{
var foo = new Foo()
{
var bar = new Bar()
foo.doFooThing()
bar.doBarThing()
}
foo.doFooThing()
bar.doBarThing() //Error
}
In the above example, foo and bar can both be accessed from within the inner scope block but when calling bar.doBarThing() in the outer scope, an error occurs as foo was dropped at the end of the inner scope.
Overview
The most basic form of scope is a block of code with it's own variables that can't be accessed outside of it like so:
In the above example,
foo
andbar
can both be accessed from within the inner scope block but when callingbar.doBarThing()
in the outer scope, an error occurs asfoo
was dropped at the end of the inner scope.Shadowing