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. LINQ
  4. Compare two lists

Compare two lists

Scheduled Pinned Locked Moved LINQ
csharplinqregexquestion
5 Posts 4 Posters 14 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.
  • A Offline
    A Offline
    akansha anku
    wrote on last edited by
    #1

    I have two lists List1 Name Id Date Value List2 Name Id Date Value I want to compare id and date for the items in two list haing same name and value fields. I want to get the items whose respective ids and dates dont match. Please suggest. How can i achieve this using LINQ.

    P M 2 Replies Last reply
    0
    • A akansha anku

      I have two lists List1 Name Id Date Value List2 Name Id Date Value I want to compare id and date for the items in two list haing same name and value fields. I want to get the items whose respective ids and dates dont match. Please suggest. How can i achieve this using LINQ.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Many, many[^] options for how to do this.

      A 1 Reply Last reply
      0
      • P Pete OHanlon

        Many, many[^] options for how to do this.

        A Offline
        A Offline
        akansha anku
        wrote on last edited by
        #3

        var resultList = (from x in list11 join y in list2 on new {x.Name,x.value} equals new {y.Name,y.value} where (x.Id != y.Id) || (x.date!= y.date) select y ); I have tried this , but this is not helping.

        M 1 Reply Last reply
        0
        • A akansha anku

          var resultList = (from x in list11 join y in list2 on new {x.Name,x.value} equals new {y.Name,y.value} where (x.Id != y.Id) || (x.date!= y.date) select y ); I have tried this , but this is not helping.

          M Offline
          M Offline
          Maciej Los
          wrote on last edited by
          #4

          Try this:

          var qry = from obj1 in List1
          join obj2 in List2 on new {obj1.Name, obj1.mValue} equals new {obj2.Name, obj2.mValue}
          where obj1.Id != obj2.Id && obj1.Date != obj2.Date
          select new{
          Name1 = obj1.Name,
          Name2 = obj2.Name,
          Id1 = obj1.Id,
          Id2 = obj2.Id,
          Date1 = obj1.Date,
          Date2 = obj2.Date,
          Value1 = obj1.mValue,
          Value2 = obj2.mValue
          };

          1 Reply Last reply
          0
          • A akansha anku

            I have two lists List1 Name Id Date Value List2 Name Id Date Value I want to compare id and date for the items in two list haing same name and value fields. I want to get the items whose respective ids and dates dont match. Please suggest. How can i achieve this using LINQ.

            M Offline
            M Offline
            mylogics
            wrote on last edited by
            #5

            You can use IComparer or IComparable interface to compare the list of objects.

            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