Loading...
Loading...
Loading...
Loading...

Finding the indices of the elements of one array in another using LINQ

View: 202    Dowload: 0   Comment: 0   Post by: admin   Category: Visual studio & .NET   Fields: Other

Given two arrays A and B, find the index from A of the element of B

Dim A As String() = {"a", "b", "c", "d", "e", "f", "g", "h", "i"}
Dim B As String() = {"b", "d", "e"}

For Each item As String In B
    Dim index1 As Integer = Array.IndexOf(A, item)
    Console.WriteLine("{0} {1}", index1, item)
Next

1 b
3 d
4 e

Here is one way...

Dim A As String() = {"a", "b", "c", "d", "e", "f", "g", "h", "i"}
Dim B As String() = {"b", "d", "e"}

Dim c = A.Select(Function(x, i) New KeyValuePair(Of String, Integer)(x, i)) _
         .Where(Function(x) B.Contains(x.Key))

For Each item In c
    Console.WriteLine("{0} - {1}", item.Key, item.Value)
Next

 

Finding the indices of the elements of one array in another using LINQ

Given two arrays A and B, find the index from A of the element of B

Posted on 08-02-2018 

Comment:

To comment you must be logged in members.

Files with category

 
File suggestion for you
File suggestion for you
File suggestion for you
File suggestion for you
Loading...
Loading...
Loading...
Loading...
File top downloads
File top downloads
File top downloads
File top downloads
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd