D
Duggi
Hi
When does a static variable come into life? Well, as far as my
knowledge goes, I think it is during the execution of static
constructor. Because thats the logic point in the program where the
usage of static variable starts.
however from the following program sample, I see that static variables
will come into existence even before the static constructor gets
invoked.
public class A
{
public static B abc = new B("from decalration");
static A()
{
abc = new B("From Constructor");
}
}
public class B
{
public B(string message)
{
Console.WriteLine(message);
}
}
public class TestPrg
{
public static void Main()
{
A a = new A();
Console.ReadLine();
}
}
Please let me know if I am wrong or your view on it.
-Cnu
When does a static variable come into life? Well, as far as my
knowledge goes, I think it is during the execution of static
constructor. Because thats the logic point in the program where the
usage of static variable starts.
however from the following program sample, I see that static variables
will come into existence even before the static constructor gets
invoked.
public class A
{
public static B abc = new B("from decalration");
static A()
{
abc = new B("From Constructor");
}
}
public class B
{
public B(string message)
{
Console.WriteLine(message);
}
}
public class TestPrg
{
public static void Main()
{
A a = new A();
Console.ReadLine();
}
}
Please let me know if I am wrong or your view on it.
-Cnu