title: Array of Classes
body: <p>I'm having a problem with my program a little bit.</p>
  
  <p>I created a class like this in my programs:</p>
  
  <pre><code>class ClassA
  {
      public int number = -1;
  
      public Random rnd = new Random();
      public void randomize()
      {
           var random = rnd;
           number = rnd.next(4)+2;
      }
  
  }
  </code></pre>
  
  <p>I was going to create and array which each of the array contain a class,
  which i created like this. I transferring the array to a new method so I can check on it.</p>
  
  <pre><code>public static void Main()
  {
      ClassA[,] arrayOfClass = new Class[6,6];
      ClassA classA= new Class();
      int i, j;
      for (i = 0; i &lt; 6; i++)
      {
           for (j = 0; j &lt; 6; j++)
           {
  
                classA.randomize();
  
                arrayOfClass[i, j] = classA;
           }
      }
      CheckClassA(arrayOfClass);
  }
  private void CheckClassA(ClassA[,] arrayOfClass)
  {
       int i,j;
       for(i=0;i&lt;6;i++)
       {
           for (j = 0; j &lt; 6; j++)
           {
           Console.Writeline("Randoming : "+arrayOfClass[i,j].number);
           {
       }
  }
  </code></pre>
  
  <p>When I run these, the console only produce the same number over and over, but different on every run, its like it only randomize it once then never randomize it again.</p>
  
  <p>My Question are:
  1. Why my program only randomize once and return the same number on all the value of the array?
  2. Does my method of transferring array wrong?</p>
  
  <p>I tried using other type below to check if my randomize failed, but no it didn't because its returning the random number as I expected.</p>
  
  <pre><code>    public static void Main()
      {
          ClassA[,] arrayOfClass = new Class[6,6];
          ClassA class= new Class();
          int i, j;
          for (i = 0; i &lt; 6; i++)
          {
               for (j = 0; j &lt; 6; j++)
               {
  
                    class.randomize();
  
                    arrayOfClass[i, j] = class;
                    Console.Writeline("Randoming : " + arrayOfClass[i,j].number);
               }
          }
      }
  </code></pre>
  
  <p>Any suggestion and help are appriciated. Thanks</p>