c#
1namespace Csp 2{ 3 class Program 4 { 5 public static void Main(String[] args) 6 { 7 try 8 { 9 new A(100); 10 } 11 catch(Exception) 12 { 13 foreach (A d in A.obj) 14 { 15 Console.WriteLine(d.num); 16 } 17 } 18 } 19 } 20 21 class A 22 { 23 public static int i = 0; 24 public static ArrayList obj = new ArrayList(); 25 public int num; 26 public A(int num) 27 { 28 if (9 < A.i) throw new Exception(); 29 else 30 { 31 this.num = num; 32 obj.Add(this); 33 A.i++; 34 } 35 } 36 } 37}
thisを理解するためにこんなコードを書きました。
100が10個表示する予定で書いたのですが、なぜ何も表示されないのですか?
またthisは未初期化のインスタンスという認識でいいですか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。