Results 1 to 5 of 5

Thread: [RESOLVED] [1.0/1.1] ArrayList<Class> vs ArrayList<String>

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Resolved [RESOLVED] [1.0/1.1] ArrayList<Class> vs ArrayList<String>

    I was just curious if I should even bother with creating a new class to hold 2 parameters of information or just hold them in an array list.
    Currently I am sorting information into any arraylist like the following.
    VB Code:
    1. ArrayList _route = new ArrayList();
    2.  
    3. _route.Add(1 + "|" + 2);
    4. _route.Add(5 + "|" + 24);
    5. _route.Add(123 + "|" + 12);
    6. // etc...

    Would it be "better" to use a class or structure and add it to the ArrayList, I only ask because it would reduce extra parsing when extracting the information but MOST importantly would it hinder the performance?

    VB Code:
    1. public class Path
    2. {
    3.      private Int32 _clid, _oid;
    4.  
    5.      public Path(Int32 CLID, Int32 OID)
    6.     {
    7.         this._clid = CLID;
    8.         this._oid = OID;
    9.     }
    10.  
    11.     public Int32 CLID
    12.    {
    13.        get { return _clid; }
    14.    }
    15.  
    16.     public Int32 OID
    17.    {
    18.        get { return _oid; }
    19.    }
    20. }
    21.  
    22. // Add information to arraylist using the path class.
    23.  
    24. ArrayList _route = new ArrayList();
    25.  
    26. _route.Add(new Path(1, 2));
    27. _route.Add(new Path(5, 24));
    28. _route.Add(new Path(123,12));
    29. // etc...

    The Path class could be instantiated up to 100+ times.

    Any ideas or thoughts would be great.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [1.0/1.1] ArrayList<Class> vs ArrayList<String>

    You should declare a structure rather than a class, but a specific type is definitely in order.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: [1.0/1.1] ArrayList<Class> vs ArrayList<String>

    That's what I expected.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [1.0/1.1] ArrayList<Class> vs ArrayList<String>

    I would expect performance to be exactly the same, since you're using 1.1 and there are no generics.

    With a generic List<Path> in 2.0 the performance would definitely be faster.

  5. #5

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: [1.0/1.1] ArrayList<Class> vs ArrayList<String>

    I did have some time today to run a time test and using a structure is faster than that just the string append so going to use a structure.


    I wish I could use generics :P

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width