Interesting question!
Think of your class as an idea. The compiler knows about your idea within itself, because it is in the same area (namespace). So there is not problem compiling.
A recursive function involves an idea put into practice. If you call a function recursively, you keep placing it onto the stack of the computer which will eventually overflow. 1
When you have a reference to a class (an idea put into practice) within itself, you are creating a pointer to a specific instance of the class (idea). So one pointer can have a reference to another pointer or even a reference to the same pointer within it.
Also, in the case of a static
(or Shared
in VB) variable, there is only a single instance of the variable for all instance of the class. You don't actually need an instance of your class to call a static member, property or function.
In summary to my ramblings: there is no recursion caused by this pattern because you never cause the class to be constructed from within a call to construct it. If your Instance property tried to call itself to get and instance, that would cause recursion.
- As an aside, the remaining space on the stack can be quite small depending on how much you have already placed on the stack. This tail-recursion logic should always be replaced with a loop: Recursive Function Calls Throw StackOverFlowException