obj
is a variable whihc is declared in the
Main
method - so it is local to that method and does not exist outside it. This is called the
scope
of a variable, and it is limited to the pair of curly brackets within which an item is declared:
if (...)
{
MyType mt = ...
...
}
You don't want access to
obj
at all within the Quiz class as the code is running with the current instance set to
this
.
Think of it like a car: you put your mobile in the glove box of your car, then we go for a drive in my car. Do you expect to find your mobile in my car's glovebox? Or any "generic car" that happens to be around?
Car is the Class, GloveBox is the variable -
this
indicates which instance of a car you are taking about: if we are in your car, then "this.Glovebox" contains your mobile. If we are in my car, then "this.GloveBox" contains a box of nitrile gloves, some spare face masks, and an umbrella - but not your mobile!