Hello everyone,
For the following code, it is correct to say that,
1. obj1 will be instialized when .NET Runtime loads class Foo and before any instance is created?
2. obj2 will be created each time we create an instance of Foo, and obj2 will be called before constructor?
My question is whether my understanding (1) and (2) are correct?
[Code]
class Foo
{
static private object obj1 = new object();
private object obj2 = new object();
public Foo()
{
}
}
[/Code]
thanks in advance,
George
George GeorgePosted Apr 14, 2008, 10:00 AM
Cool Alan, question answered!
regards,
George
AlanPosted Apr 14, 2008, 9:49 AM
You're right on the first one and almost right on the second one.
Strictly speaking, obj2 will be initialized just after the constructor is called but before any code in the constructor is executed and before the implicit call to the base class constructor which occurs next.