ふらっとC#,C♯,C#(初心者用) Part37
■ このスレッドは過去ログ倉庫に格納されています
0157デフォルトの名無しさん
2009/02/09(月) 19:37:14t1の後ろにも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();
}
}
■ このスレッドは過去ログ倉庫に格納されています