09/02/09 19:37:14
ありがとうございます!
t1の後ろにもConsole.ReadLine();を入れて静動両方のコンストラクタが呼ばれているのが確認できました。
しかし、これがうまくコンパイルできませんお願いします
class Test
{
static int i;
static Test() {
i = 100;
Console.WriteLine(@"staticコンストラクタ i={0}", i);
}
public Test() {
Console.WriteLine(@"コンストラクタ1 i={0}", ++i);
}
public Test(string str) {
Console.WriteLine(@"コンストラクタ2 i={0}", ++i);
}
}
class test2 : Test {
test2()
: base(str) { }
}
class Program {
static void Main(string[] args) {
Test t1 = new Test();
Console.ReadLine();
Test t2 = new Test("test");
Console.ReadLine();
test2 t3 = new test2("test");
Console.ReadLine();
}
}