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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Searching through an ArrayList

Searching through an ArrayList

Scheduled Pinned Locked Moved C#
algorithmstutorial
5 Posts 3 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.
  • D Offline
    D Offline
    Darkness84
    wrote on last edited by
    #1

    I have an arraylist that contains objects who themselves contain multiple properties. I would like to know is there are faster way than using a for loop to search through an arraylist to find the object whose certain property matches what I am looking for. An example of what I am currently doing is listed below. for(int p = 0; p < SupplierItemDataStore.Count; p++) { if(stock.Code == ((XMLDefs.SupplierItem.SupplierItem)SupplierItemDataStore[p]).StockCode) { { //Do stuff here } } } where stock is the object that is passed in and SupplierItemDataStore contains over 31,000 items.

    M G D 3 Replies Last reply
    0
    • D Darkness84

      I have an arraylist that contains objects who themselves contain multiple properties. I would like to know is there are faster way than using a for loop to search through an arraylist to find the object whose certain property matches what I am looking for. An example of what I am currently doing is listed below. for(int p = 0; p < SupplierItemDataStore.Count; p++) { if(stock.Code == ((XMLDefs.SupplierItem.SupplierItem)SupplierItemDataStore[p]).StockCode) { { //Do stuff here } } } where stock is the object that is passed in and SupplierItemDataStore contains over 31,000 items.

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      I don't think that there will be more faster way. foreach(XMLDefs.SupplierItem.SupplierItem sItem in SupplierItemDataStore){ if(stock.Code = sItem.StockCode){ } } There are a lot of C# gurus in our forum.. let's see what they say..

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      1 Reply Last reply
      0
      • D Darkness84

        I have an arraylist that contains objects who themselves contain multiple properties. I would like to know is there are faster way than using a for loop to search through an arraylist to find the object whose certain property matches what I am looking for. An example of what I am currently doing is listed below. for(int p = 0; p < SupplierItemDataStore.Count; p++) { if(stock.Code == ((XMLDefs.SupplierItem.SupplierItem)SupplierItemDataStore[p]).StockCode) { { //Do stuff here } } } where stock is the object that is passed in and SupplierItemDataStore contains over 31,000 items.

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        If you put the data in a HashTable with the stock code as key, you can locate the item very quickly. If you use framework 2.0 you would use a Dictionary instead of a HashTable.

        --- single minded; short sighted; long gone;

        M 1 Reply Last reply
        0
        • G Guffa

          If you put the data in a HashTable with the stock code as key, you can locate the item very quickly. If you use framework 2.0 you would use a Dictionary instead of a HashTable.

          --- single minded; short sighted; long gone;

          M Offline
          M Offline
          Michael Sync
          wrote on last edited by
          #4

          >>If you put the data in a HashTable with the stock code as key, you can locate the item very quickly. Yeah. Great Idea. Thanks..

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

          1 Reply Last reply
          0
          • D Darkness84

            I have an arraylist that contains objects who themselves contain multiple properties. I would like to know is there are faster way than using a for loop to search through an arraylist to find the object whose certain property matches what I am looking for. An example of what I am currently doing is listed below. for(int p = 0; p < SupplierItemDataStore.Count; p++) { if(stock.Code == ((XMLDefs.SupplierItem.SupplierItem)SupplierItemDataStore[p]).StockCode) { { //Do stuff here } } } where stock is the object that is passed in and SupplierItemDataStore contains over 31,000 items.

            D Offline
            D Offline
            Darkness84
            wrote on last edited by
            #5

            Thanks for your help guys. The hash table is the way I'm going to have to go as the application I'm developing is on Framework 1.1 so I can't use a Dictionary.

            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