I am looking at some code written by a colleague, and what I expected is not. Here is the code:
public class SingletonClass { private static readonly SingletonClass _instance = new SingletonClass(); public static SingletonClass Instance { get { return _instance; } } private SingletonClass() {
In another class, I expected what I could do:
private SingletonClass sc = SingletonClass.Instance.Instance.Instance.Instance.Instance.Instance;
and refers to the same instance of this class. What happens, I can only get one .Instance
. Something I did not expect. If the Instance
property returns a SingletonClass
class, why can't I call the Instance
property on the returned class, etc. Etc.?
source share