title: C# populate array with unique ints No Linq or ArrayLists;
body: <p>This code is buggy but can't figure out why ... want to populate an array with 7 unique random integers without using arraylists or linq! I know the logic is not okay... </p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {    int current;
           int[] numbers = new int[7];  // size of that array 
           Random rNumber = new Random();
           current = rNumber.Next(1, 50);
           numbers[0] = current;
           Console.WriteLine("current number is {0}", current);
           for (int i=1;i&lt;7;i++)
           {
               current = rNumber.Next(1, 50);
               for (int j = 0; j &lt; numbers.Length; j++)
               {
                   do
                   {
                       if (current == numbers[j])
                       {
                           Console.WriteLine("Duplicate Found");
                           current = rNumber.Next(1, 50);
                       }
                       else
                       {   
                           numbers[j++] = current;
                           break;
                       }
                   }while (current == numbers[j]);
  
               }//inner for
  
           }//outer for
           for (int l = 0; l &lt; 7; l++) // DISPLAY NUMBERS
           {
               Console.WriteLine(numbers[l]);
           }
  
      }// main
   }//class
  </code></pre>