Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. .NET adding things to ArrayList at random

.NET adding things to ArrayList at random

Scheduled Pinned Locked Moved C#
debuggingcsharpdata-structureshelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kayhustle
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups