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. Web Development
  3. ASP.NET
  4. List<> collections

List<> collections

Scheduled Pinned Locked Moved ASP.NET
questiontutorial
10 Posts 5 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.
  • S Offline
    S Offline
    Satish_S
    wrote on last edited by
    #1

    I have 2 list collections as below List1 115 100 150 List2 115 100 now i need to check both of above list and need to get answer for matched , for example : 115 100 both matched, i need to achieve this how can i do it ?

    D L 2 Replies Last reply
    0
    • S Satish_S

      I have 2 list collections as below List1 115 100 150 List2 115 100 now i need to check both of above list and need to get answer for matched , for example : 115 100 both matched, i need to achieve this how can i do it ?

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      See if this works for you ... Vote 5 if it does.

      Dim listA, listB, listC As New List(Of Integer)
      Dim i As Integer

         listA.Add(115)
         listA.Add(100)
         listA.Add(150)
      
         listB.Add(115)
         listB.Add(100)
      
         For i = 0 To listA.Count - 1
             If (listB.Contains(listA(i))) Then
                 listC.Add(listA(i))
             End If
         Next
      
         For i = 0 To listC.Count - 1
             Debug.Print("The following items are common to both lists: " & CStr(listC(i)))
         Next
      
      L S 2 Replies Last reply
      0
      • D David Mujica

        See if this works for you ... Vote 5 if it does.

        Dim listA, listB, listC As New List(Of Integer)
        Dim i As Integer

           listA.Add(115)
           listA.Add(100)
           listA.Add(150)
        
           listB.Add(115)
           listB.Add(100)
        
           For i = 0 To listA.Count - 1
               If (listB.Contains(listA(i))) Then
                   listC.Add(listA(i))
               End If
           Next
        
           For i = 0 To listC.Count - 1
               Debug.Print("The following items are common to both lists: " & CStr(listC(i)))
           Next
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        List.Intersect[^] does this for you.

        D W 2 Replies Last reply
        0
        • L Lost User

          List.Intersect[^] does this for you.

          D Offline
          D Offline
          David Mujica
          wrote on last edited by
          #4

          very cool. I'm living in the dark ages (.NET 2.0), so this feature was available. Good to know. :thumbsup:

          T 1 Reply Last reply
          0
          • D David Mujica

            See if this works for you ... Vote 5 if it does.

            Dim listA, listB, listC As New List(Of Integer)
            Dim i As Integer

               listA.Add(115)
               listA.Add(100)
               listA.Add(150)
            
               listB.Add(115)
               listB.Add(100)
            
               For i = 0 To listA.Count - 1
                   If (listB.Contains(listA(i))) Then
                       listC.Add(listA(i))
                   End If
               Next
            
               For i = 0 To listC.Count - 1
                   Debug.Print("The following items are common to both lists: " & CStr(listC(i)))
               Next
            
            S Offline
            S Offline
            Satish_S
            wrote on last edited by
            #5

            Hi thanks worked. voted 5

            L 1 Reply Last reply
            0
            • D David Mujica

              very cool. I'm living in the dark ages (.NET 2.0), so this feature was available. Good to know. :thumbsup:

              T Offline
              T Offline
              the headless nick
              wrote on last edited by
              #6

              David Mujica wrote:

              very cool.
               
              I'm living in the dark ages (.NET 2.0), so this feature was available.

              :laugh: :laugh: :laugh: DARK AGES OF 2.0 HA HA HAAA

              1 Reply Last reply
              0
              • S Satish_S

                I have 2 list collections as below List1 115 100 150 List2 115 100 now i need to check both of above list and need to get answer for matched , for example : 115 100 both matched, i need to achieve this how can i do it ?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Try List.Intersect[^].

                T 1 Reply Last reply
                0
                • S Satish_S

                  Hi thanks worked. voted 5

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  There's a better way to do this, check my answer.

                  1 Reply Last reply
                  0
                  • L Lost User

                    Try List.Intersect[^].

                    T Offline
                    T Offline
                    the headless nick
                    wrote on last edited by
                    #9

                    Cool indeed.. :thumbsup:

                    1 Reply Last reply
                    0
                    • L Lost User

                      List.Intersect[^] does this for you.

                      W Offline
                      W Offline
                      Wonde Tadesse
                      wrote on last edited by
                      #10

                      Good answer!

                      Wonde Tadesse MCTS

                      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