.NET adding things to ArrayList at random
-
I have a two classes A and B
public class A { private static ArrayList allobjects=new ArrayList(); private static int objcount=0; public A() { objcount++; allobjects.Add(this); } public static A[] AllObjects { get{return allobjects.ToArray(typeof(A)) as A[];} } } public class B:A { public B()//automatically calls base constructor A {} }
When I construct a B object it is added to the allobjects array fine. However at random times, when I look at A.AllObjects in the debugger, there are more objects than what I added. For example if I construct one and I look at it there will be 7 in the array. Furthermore, if I look at A.allobjects[0].allobjects, this array will contain 13, if I go further I'll get 19 and so forth. If I put a breakpoint in the constructor, it never hits the breakpoint, yet objcount will reflect the number of objects in the array depending on how deep I go. So any A.allobjects[0].objcount=7, and A.allobjects.[0].allobjects[0].objcount=13 and so forth. This is bugging me out especially since I have a breakpoint in the constructor and that is the only place that objcount is incremented. Any help would be greatly appreciated. K