title: Using objects from one class in another class
body: <p>I have two classes <code>Teacher</code> and <code>Student</code>.  I am trying to get teacher to use the class functions in students.  The problem I am having is that I need the number of student object being used in <code>Teacher</code> to be random.  I thought I figured this out in the constructor, but I had to declare new student object in every function of teacher that I use student.  So that just creates a new student object which does me no good.  Here is my code</p>
  
  <pre><code>class Teacher
  {
      private bool absence;
      private bool level;
      private static int uniqueID = 0;
      private ArrayList arrayList = new ArrayList();
      private ArrayList arrayList1 = new ArrayList();
      private int id = 0;
      private int numPages;
      private char present;
      Random random = new Random();
      int randomLevel = random.Next(20, 30);//this line does not work, if I could then I would just use randomLevel in the in the line below for creating my student objects
      Student student = new Student();
      int maybe;
  
      public Teacher()
      {
          int randomLevel = random.Next(1, 3);
          id = uniqueID;
          absence = false;
          level = (randomLevel % 2 == 0);
          uniqueID++;
          randomLevel = random.Next(20, 30);
          Student[] student = new Student[randomLevel];
          maybe = randomLevel;
          for (int i = 0; i &lt; randomLevel; i++)
          {
              student[i] = new Student();
          }
      }
  </code></pre>
  
  <p>and here is a function in teacher that uses student</p>
  
  <pre><code>  public void addPages()//Come back need to add specific child
    {
          int choice = 0;
          Console.WriteLine("Enter the student ID");
          choice = int.Parse(Console.ReadLine());
          Student[] student= new Student[maybe];//If i get rid of this line then how will I choose which student object to use.  However this created a new student object and I do not want to do that
  
          student[choice] = new Student();
          int number = 0;
          if (student[choice].absent())
          {
              number = student[choice].excused();
          }
          else
          {
  
              Console.WriteLine("How many pages did the student read today? ");
              number = int.Parse(Console.ReadLine());
          }
          student[choice].add(number);           
     }
  </code></pre>
  
  <p>Is there a way to get the random to work in the declaration area above the constructor?</p>