Compare arraylist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irobot
    New Member
    • Jun 2009
    • 1

    Compare arraylist

    Hi.
    I would like to ask how to compare three or more Arraylists?
    I need to dublicate ellements from Arraylists, in order to filter datagridview.
    I would like to choose from 1 to 5 Arraylists. I know how to compare two Aarraylists.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Would this make sense/work for you?

    Compare A-B
    Compare B-C
    Compare C-D
    Compare D-E

    Comment

    • PRR
      Recognized Expert Contributor
      • Dec 2007
      • 750

      #3
      Look into ArrayList contains and equals method

      Code:
      public static void CompareArrayList()
              {
                  ArrayList al = new ArrayList();
                  al.Add(1);
                  al.Add("2");
      
                  ArrayList al1 = new ArrayList();
                  al1.Add(1);
                  al1.Add("2");
      
                  bool isEqual = true ;
      
                  if (al.Count == al1.Count)
                  {
                      for(int i=0;i<al.Count;i++)
                      {
                          if (al[i] .Equals( al1[i])==false)
                          {
                              isEqual = false;
                              break;
                          }
                      }
                 }
      // OR you could use Contains method
      if (al.Count == al1.Count)
                  {
                      for (int i = 0; i < al.Count; i++)
                      {
                          if (al1.Contains(al[i])==false)
                          {
                              isEqual = false;
                              break;                        
                          }
                     }
                }
             }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Your description doesn't really say what you want to do.
        Why not post an example of input lists and expected output from those input lists.

        Comment

        Working...