Hey folks,
I have a question about singletons that I think I know the answer to...but every time the scenario pops-up I kinda second guess myself a little so I would like to know the concrete answer.
Say I have two classes setup as so...
public class ClassA
{
private static ClassA _classA;
public static ClassA Instance { get { return _classA ?? LoadClassA(); } }
private ClassA(){}
public static ClassA LoadClassA()
{
_classA = new ClassA();
return _classA;
}
private ClassB _classB = new ClassB();
public ClassB ClassB { get { return _classB; } set { _classB = value; } }
}
public class ClassB
{
}
My question is simple.
I'm wondering if the _classB field is treated as static as well if I access the singleton for ClassA? Even though I didn't declare _classB as a static member.
I've always basically just guessed that _classB it is treated as static (one memory location) but I would like to know for sure. Am I wrong? Is a new object created for _classB every time you access it from singleton ClassA...even though there is only one ClassA in memory? Or is it because I newed up _classB on the declaration that causes there to be only one instance of it?
Thanks in advance, -Matt