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. problem with List and FindAll()

problem with List and FindAll()

Scheduled Pinned Locked Moved C#
helpquestion
4 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
    dfn
    wrote on last edited by
    #1

    Hello. Before I describe my dilemma, here's my code, roughly: List allEntries = new List(); // fill allEntries with ArrayLists // each ArrayList entered is at *least* of size 4 // allEntries.Count is 3 for (byte i = 0; i < 2; i++) { List goodEntries = allEntries.FindAll(delegate(ArrayList al) { return((byte)al[0] == i); }); // do stuff } // for The problem: inside the anonymous function, al[0] sometimes gives the values of al[1]. I need it to only compare the values of al[0], never al[1]. I have seen code where the delegate is an object from a user-created class (ex: (delegate(Cars c) { return(c.plateNum < 123); });). What exactly am I doing wrong? Any help or advice is appreciated!

    C E D 3 Replies Last reply
    0
    • D dfn

      Hello. Before I describe my dilemma, here's my code, roughly: List allEntries = new List(); // fill allEntries with ArrayLists // each ArrayList entered is at *least* of size 4 // allEntries.Count is 3 for (byte i = 0; i < 2; i++) { List goodEntries = allEntries.FindAll(delegate(ArrayList al) { return((byte)al[0] == i); }); // do stuff } // for The problem: inside the anonymous function, al[0] sometimes gives the values of al[1]. I need it to only compare the values of al[0], never al[1]. I have seen code where the delegate is an object from a user-created class (ex: (delegate(Cars c) { return(c.plateNum < 123); });). What exactly am I doing wrong? Any help or advice is appreciated!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Why are you using ArrayList at all ? What is al ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • D dfn

        Hello. Before I describe my dilemma, here's my code, roughly: List allEntries = new List(); // fill allEntries with ArrayLists // each ArrayList entered is at *least* of size 4 // allEntries.Count is 3 for (byte i = 0; i < 2; i++) { List goodEntries = allEntries.FindAll(delegate(ArrayList al) { return((byte)al[0] == i); }); // do stuff } // for The problem: inside the anonymous function, al[0] sometimes gives the values of al[1]. I need it to only compare the values of al[0], never al[1]. I have seen code where the delegate is an object from a user-created class (ex: (delegate(Cars c) { return(c.plateNum < 123); });). What exactly am I doing wrong? Any help or advice is appreciated!

        E Offline
        E Offline
        Expert Coming
        wrote on last edited by
        #3

        Sometimes al[0] is returning the result of al[1], are you sure they are not equal in that situation?

        The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo

        1 Reply Last reply
        0
        • D dfn

          Hello. Before I describe my dilemma, here's my code, roughly: List allEntries = new List(); // fill allEntries with ArrayLists // each ArrayList entered is at *least* of size 4 // allEntries.Count is 3 for (byte i = 0; i < 2; i++) { List goodEntries = allEntries.FindAll(delegate(ArrayList al) { return((byte)al[0] == i); }); // do stuff } // for The problem: inside the anonymous function, al[0] sometimes gives the values of al[1]. I need it to only compare the values of al[0], never al[1]. I have seen code where the delegate is an object from a user-created class (ex: (delegate(Cars c) { return(c.plateNum < 123); });). What exactly am I doing wrong? Any help or advice is appreciated!

          D Offline
          D Offline
          dfn
          wrote on last edited by
          #4

          First, I apologize. My code was not correct, and I'm sure that added to the confusion. Now, al is ArrayList al, and the reason I need al[0] is to see if two ArrayLists contained in "allEntries" have the same value stored in index 0. I have tried it when al[0] and al[1] contain the same values, and when they contain different values. The result is the same, ie, in the anonymous function, al[0] sometimes gives the values of al[1]. Here is my code again: List allEntries = new List(); byte id0 = 0, id1 = 1; byte sid1 = 16, sid2 = 88, sid3 = 100; ArrayList entry1 = new ArrayList(); ArrayList entry2 = new ArrayList(); ArrayList entry3 = new ArrayList(); entry1.Add(id0); entry1.Add(sid1); entry1.Add("John"); entry1.Add("Doe"); entry2.Add(id1); entry2.Add(sid2); entry2.Add("Jane"); entry2.Add("Doe"); entry3.Add(id0); // notice index 0 of entry3 and entry1 contains id0 entry3.Add(sid3); entry3.Add("Joe"); entry3.Add("Doe"); allEntries.Add(entry1); allEntries.Add(entry2); allEntries.Add(entry3); for (byte i = 0; i < 2; i++) { List sameIdEntries = allEntries.FindAll(delegate(ArrayList al) { return((byte)al[0] == i); }); // do stuff } // for Any help is appreciated!

          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