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. comparing two arrays

comparing two arrays

Scheduled Pinned Locked Moved C#
data-structures
3 Posts 2 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.
  • R Offline
    R Offline
    rameshdontagani
    wrote on last edited by
    #1

    hi, i have two arrays.. first arraylist consists of 1,2,4,6,8; second arraylist consists of 2,6,9,8 i got the commoon items using the following code..it is working fine for(int i=0;i<strOldItems.Length;i++) { strTest[i]=strOldItems[i]; for(int j=0;j<strNewItems.Length;j++) { if(strTest[i]==strNewItems[j]) { if(strCommon.Length>0) { strCommon=strCommon+","+ strTest[i]; //Response.Write(strTest[i]+","); } else { strCommon=strTest[i]; } } but i need the items which is in first array and which is not in second array..for that i wrote the following code..but it is not working.. for(int i=0;i<strOldItems.Length;i++) { strTest[i]=strOldItems[i]; for(int j=0;j<strNewItems.Length;j++) { if(strTest[i]!=strNewItems[j]) { if(strReject.Length>0) { strReject=strReject+","+ strTest[i]; //Response.Write(strTest[i]+","); } else { strReject=strTest[i]; } } } }

    S 1 Reply Last reply
    0
    • R rameshdontagani

      hi, i have two arrays.. first arraylist consists of 1,2,4,6,8; second arraylist consists of 2,6,9,8 i got the commoon items using the following code..it is working fine for(int i=0;i<strOldItems.Length;i++) { strTest[i]=strOldItems[i]; for(int j=0;j<strNewItems.Length;j++) { if(strTest[i]==strNewItems[j]) { if(strCommon.Length>0) { strCommon=strCommon+","+ strTest[i]; //Response.Write(strTest[i]+","); } else { strCommon=strTest[i]; } } but i need the items which is in first array and which is not in second array..for that i wrote the following code..but it is not working.. for(int i=0;i<strOldItems.Length;i++) { strTest[i]=strOldItems[i]; for(int j=0;j<strNewItems.Length;j++) { if(strTest[i]!=strNewItems[j]) { if(strReject.Length>0) { strReject=strReject+","+ strTest[i]; //Response.Write(strTest[i]+","); } else { strReject=strTest[i]; } } } }

      S Offline
      S Offline
      Sathesh Sakthivel
      wrote on last edited by
      #2

      Did you check by applying the break point aah? did you get the value or not? And what error it shows?

      SSK. Anyone who says sunshine brings happiness has never danced in the rain.

      R 1 Reply Last reply
      0
      • S Sathesh Sakthivel

        Did you check by applying the break point aah? did you get the value or not? And what error it shows?

        SSK. Anyone who says sunshine brings happiness has never danced in the rain.

        R Offline
        R Offline
        rameshdontagani
        wrote on last edited by
        #3

        hi, it is not giving any error, to get the same values from the two arrays ..i wrote the logic like this, first array first element checks with all the second array elemnts..if it find any matches ..it returns the matched value..like second element with all the elements of second array. but to get the elemenet which is in first array and which is not second array.. i wrote like this, first array element checks with the all the elements in the second array..if he does not found any matches it returns the unmatched values ....this is wrong na..becasue this first elemnt unmacthedvalues may be equal to the second element in the first array how can i write the logic for this

        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