title: search within an array with a condition
body: <p>I have two array I'm trying to compare at many levels. Both have the same structure with 3 "columns.</p>
  
  <p>The first column contains the polygon's ID, the second a area type, and the third, the percentage of each area type for a polygone.</p>
  
  <p>So, for many rows, it will compare, for example, ID : 1 Type : aaa % : 100
  But for some elements, I have many rows for the same ID. For example, I'll have ID 2, Type aaa, 25% --- ID 2, type bbb, 25% --- ID 2, type ccc, 50%. And in the second array, I'll have  ID 2, Type aaa, 25% --- ID 2, type bbb, 10% --- ID 2, type eee, 38% --- ID 2, type fff, 27%.</p>
  
  <p>here's a visual example..
  <img src="https://i.stack.imgur.com/yTEqg.jpg" alt="PrintScreen"></p>
  
  <p>So, my function has to compare these two array and send me an email if there are differences.
  (I wont show you the real code because there are 811 lines). The first "if" condition is </p>
  
  <pre><code>if array1.id = array2.id Then
  if array1.type = array2.type Then
  if array1.percent = array2.percent Then
  zone_verification = True
  Else
  zone_verification = False
  </code></pre>
  
  <p>The probleme is because there are more than 50 000 rows in each array. So when I run the function, for each "array1.id", the function search through 50 000 rows in array2. 50 000 searchs for 50 000 rows.. it's pretty long to run!</p>
  
  <p>I'm looking for something to get it running faster. How could I get my search more specific. Example : I have many id "2" in the array1. If there are many id "2" in the array2, find it, and push all the array2.id = 3 in a "sub array" or something like that, and search in these specific rows. So I'll have just X rows in array1 to compare with X rows in array 2, not with 50 000. and when each "id 2" in array1 is done, do the same thing for "id 4".. and for "id 5"...</p>
  
  <p>Hope it's clear. it's almost the first time I use VB.net, and I have this big function to get running. </p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here's what I wanna do.</p>
  
  <p>I have two different layers in a geospatial database. Both layers have the same structure. They are a "spatial join" of the land parcels (55 000), and the land use layer. The first layer is the current one, and the second layer is the next one we'll use after 2015.</p>
  
  <p>So I have, for each "land parcel" the percentage of each land use. So, for a "land parcel" (ID 7580-80-2532, I can have 50% of farming use (TYPE FAR-23), and 50% of residantial use (RES-112). In the first array, I'll have 2 rows with the same ID (7580-80-2532), but each one will have a different type (FAR-23, RES-112) and a different %. 
  In the second layer, the same the municipal zoning (land use) has changed. So the same "land parcel" will now be 40% of residential use (RES-112), 20% of commercial (COM-54) and 40% of a new farming use (FAR-33).
  So, I wanna know if there are some differences. Some land parcels will be exactly the same. Some parcels will keep the same land use, but not the same percentage of each. But for some land parcel, there will be more or less land use types with different percentage of each.</p>
  
  <p>I want this script to compare these two layers and send me an email when there are differences between these two layers for the same land parcel ID.</p>
  
  <p>The script is already working, but it takes too much time. </p>
  
  <p>The probleme is, I think, the script go through all array2 for each row in array 1. </p>
  
  <p>What I want is when there are more than 1 rows with the same ID in array1, take only this ID in both arrays.</p>
  
  <p>Maybe if I order them by IDs, I could write a condition. kind of "when you find what you're looking for, stop searching when you'll find a different value?</p>
  
  <p>It's hard to explain it clearly because I've been using VB since last week.. And english isn't my first language! ;)</p>