Who among us hasn't had to scan a list looking for particular items? Sometimes, as you discover more and more items of interest, you need to explicitly resize the target list to hold them.

From the Bible of MSDN:

"This method allocates a new array with the specified size, copies elements from the old array to the new one, and then replaces the old array with the new one."

Naturally, since this is fairly expensive, you want to do it as infrequently as possible.

Our friend, A. Dev discovered this O(n^2) gem written by the boss' nephew.

We've all heard variants of the phrase: There's the right way, the wrong way, and the Army way....

I give you: The Nephew Way:

public static Measure[] digitalFilter(...) { 
  // OP: yy is the size of the arrays
  for (int ii = 0; ii <= sonar_data_l - 3; ii++) { 
      for (int kkk = ii; kkk < dm; kkk++) { 
          if (sonar_o[kkk]>sonar_min && sonar_o[kkk] <= sonar_max_err) { 
             if ((xx = Array.BinarySearch(sonar, (int)sonar_o[kkk])) < 0) { 
               Array.Resize(ref freq, yy + 1); 
               Array.Resize(ref sonar, yy + 1);  
               Array.Sort(sonar, freq); 
               xx = Array.BinarySearch(sonar, (int)sonar_o[kkk]); 
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!