Storing Objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hunter

    Storing Objects

    Hi,

    In one of my forms I need hold an array of objects (same class) that is
    dynamic at runtime. Instead of using an array I am looking at ArrayList or
    Hashtable. Any suggestions?


  • Andy

    #2
    Re: Storing Objects

    If you're using .Net 2.0, try a generic list, such as List<Tor
    Dictionary<T>.

    Either way, don't expose the collection outside the class (if you're
    buidling something as part of a library).

    Andy

    Hunter wrote:
    Hi,
    >
    In one of my forms I need hold an array of objects (same class) that is
    dynamic at runtime. Instead of using an array I am looking at ArrayList or
    Hashtable. Any suggestions?

    Comment

    • apathetic

      #3
      Re: Storing Objects

      Hunter wrote:
      In one of my forms I need hold an array of objects (same class) that is
      dynamic at runtime. Instead of using an array I am looking at ArrayList or
      Hashtable. Any suggestions?
      If you are using .NET 2.0, go for a generic collection such as List<T>.
      You pass your class name to it when creating the collection, so it's
      totally typesafe. You also skip the effort involved in casting back to
      the right class when getting data out.

      List<MyClasslis t = new List<MyClass>() ;

      apathetic

      Comment

      • Bruce Wood

        #4
        Re: Storing Objects


        Hunter wrote:
        Hi,
        >
        In one of my forms I need hold an array of objects (same class) that is
        dynamic at runtime. Instead of using an array I am looking at ArrayList or
        Hashtable. Any suggestions?
        If you need to store the objects by key and then get an object back
        given its key, then use a Hashtable.

        If you just want to get at the objects by index, or just need a list
        you can iterate over, use an ArrayList or, better yet, List<Tin .NET
        2.0.

        If you need both a key lookup and to maintain the objects in a
        particular order, use a SortedList.

        Comment

        Working...