title: How to search for a range of values within an array C#
body: <p>I'm still new to C# and I got stuck on one of functionality in my code. I cannot get it to return the values in 'case6', search for age within range (min-max), everything else works fine. What's wrong there?</p>
  
  <pre><code>class Buss
  {
      private string name = "minibuss";
      public int[] passengers = new int[9];
      public int passengerNum;
  
      public void Run()  //that´s the menu, you fill in age and then could go through array with other options
      {
          Console.WriteLine("THE miniBUSS SIMULATOR");
  
          int temp = 0;
          do
          {
              Console.WriteLine("Choose an alternative (starting with 1 ;-))");
              Console.WriteLine("1. Fill in pass");
              Console.WriteLine("2. Print passengers age");
              Console.WriteLine("3. Show total age of all passanger");
              Console.WriteLine("4. Average age of passsangers");
              Console.WriteLine("5. Who´s oldest");
              Console.WriteLine("6. Show passangers within range of years");
              Console.WriteLine("7. Sort passangers by age");
              Console.WriteLine("Hit 0 to exit\n");
              temp = int.Parse(Console.ReadLine());
  
              switch (temp)
              {
                  case 1:
                      add_passenger();
                      break;
                  case 2:
                      print_buss();
                      break;
                  case 3:
                      calc_total_age();
                      break;
                  case 4:
                      calc_average_age();
                      break;
                  case 5:
                      max_age();
                      break;
                  case 6:
                      find_age();
                      break;
                  case 7:
                      sort_buss();
                      break;
                  case 0:
                      Console.WriteLine("Press any key to continue");
                      break;
                  default:
                      Console.WriteLine("Use number between 0 and 7");
                      break;
              }
          } while (temp != 0);
      }
  
      public void add_passenger()
      {
          for (int i = 0; i &lt; passengers.Length; i++)
          {
              Console.WriteLine("Age of passenger {0}", i);
              if (int.TryParse(Console.ReadLine(), out int result) &amp;&amp; result &gt;= 0 &amp;&amp; result &lt;= 122)
              {
                  passengers[i] = result;
              }
              else
              {
                  i--;
                  Console.WriteLine("Max age is 122");
              }
          }
      }
  
      public void print_buss()
      {
          foreach (int temp in passengers)
          {
              Console.WriteLine(temp);
          }
      }
  
      public void calc_total_age()
      {
          int sum = 0;
          for (int i = 0; i &lt; passengers.Length; i++)
          {
              sum += passengers[i];
          }
          Console.WriteLine("Total age is " + sum);
      }
  
      public void calc_average_age()
      {
          int sum = 0;
          for (int i = 0; i &lt; passengers.Length; i++)
          {
              sum += passengers[i];
          }
          int avr = sum / passengers.Length;
  
          Console.WriteLine("Avarage age is " + avr);
      }
  
      public void max_age()
      {
          int max = passengers.Max();
          Console.WriteLine(max);
      }
  
      public void find_age()
      {
          Console.WriteLine("Write the lower limit for your range: ");
          int keyMin = int.Parse(Console.ReadLine());                      // say 10
          Console.WriteLine("Write the highest value for your range: ");
          int keyMax = int.Parse(Console.ReadLine());                      // ex. 30 so range is 10 - 30 
  
          for (int i = 0; i &lt; passengers.Length; i++)            
          {
              if (passengers[i] &gt;=  keyMin &amp;&amp; passengers[i] &lt;= keyMax)   
  
  //I´ve tried different options for that loop but without succes, do I
  // need to call sort_buss() method first?
  
              {
                  Console.WriteLine("Those are the passangers within range: " + i);
              }
              break;
          }
          Console.WriteLine("Nothing to return\n");   //That´s what program returns each time
      }
  
      public void sort_buss()
      {
          int max = passengers.Length - 1;
  
          for (int i = 0; i &lt; max; i++)
          {
              int nrLeft = max - i;
  
              for (int j = 0; j &lt; nrLeft; j++)
              {
                  if (passengers[j] &gt; passengers[j + 1])
                  {
                      int temp = passengers[j];
                      passengers[j] = passengers[j + 1];
                      passengers[j + 1] = temp;
                  }
              }
          }
          for (int i = 0; i &lt; passengers.Length; i++)
          Console.WriteLine("\n Passengers sorted by age ", passengers[i]);
      }
  }
  
  class Program
  {
      public static void Main(string[] args)
      {
          var minbuss = new Buss();
          minbuss.Run();
          Console.ReadKey(true);
      }
  }
  </code></pre>
  
  <p>}</p>