title: Using OpenFileDialog and StreamReader
body: <p>There are two classes, one to cover the form (class 1) and the other to cover what gets displayed on the form (class 2).  I'm trying to call a method in class 1 from class 2 to display certain information in a text box.  I keep getting the error:</p>
  
  <blockquote>
    <p>An object reference is required for the non-static field, method, or property</p>
  </blockquote>
  
  <p>I've encountered this error before and been able to make it through, but nothing I've attempted so far has helped in this instance.  I'm posting code for both the classes.</p>
  
  <p>Class 1:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Forms;
  
  namespace Project6
  {
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
  
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          Stream myStream = null;
  
          //Create an instance of the open file dialog box
          OpenFileDialog ofd = new OpenFileDialog();
  
          //Set parameters, filter options, and filter index
          ofd.InitialDirectory = "c:\\";
          ofd.Filter = "Text Files (.txt)|*.txt";
          ofd.FilterIndex = 2;
  
          ofd.Multiselect = false;
  
          if (ofd.ShowDialog() == DialogResult.OK)
          {
              try
              {
                  if ((myStream = ofd.OpenFile()) != null)
                  {
                      using (myStream = ofd.OpenFile())
                      {
                          StreamReader reader = new StreamReader(myStream);
  
                          string studentInformation = "";
                          string[] studentInformationArray = new string[11];
                          studentInformation = reader.ReadLine();
  
                          while ((studentInformation = reader.ReadLine()) != null)
                          {
                              studentInformationArray = studentInformation.Split(',');
                              Student newStudent = new Student(studentInformationArray);
                          }
                      }
                  }
              }
              catch (Exception ex)
              {
                  MessageBox.Show("Error: Could not read file from disk.  Original error: " + ex.Message);
              }
          }
      }
  
      private void textBox1_TextChanged(object sender, EventArgs e)
      {
          textBox1.Text = Student.GetName(); //This generates the compiler error
          textBox1.Select(6, 5);
          MessageBox.Show(textBox1.SelectedText);
      }
  }
  }
  </code></pre>
  
  <p>Class 2:</p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  
  namespace Project6
  {
  class Student
  {
      //Initialize variables
      private string[] studentInformationArray;
  
      //Constructor that accepts the studentInformationArray as an argument
      public Student(string[] studentInformationArray)
      {
          this.studentInformationArray = studentInformationArray;
      }
  
      public Student()
      {
          string className = studentInformationArray[1];
          string semester = studentInformationArray[2];
          string picture = studentInformationArray[3];
          int project1 = Convert.ToInt32(studentInformationArray[4]);
          int project2 = Convert.ToInt32(studentInformationArray[5]);
          int project3 = Convert.ToInt32(studentInformationArray[6]);
          int project4 = Convert.ToInt32(studentInformationArray[7]);
          int project5 = Convert.ToInt32(studentInformationArray[8]);
          int project6 = Convert.ToInt32(studentInformationArray[9]);
          int midtermExam = Convert.ToInt32(studentInformationArray[10]);
          int finalExam = Convert.ToInt32(studentInformationArray[11]);
      }
  
      public string GetName()
      {
          string studentName;
          studentName = studentInformationArray[0];
          return studentName;
      }
  
  }
  
  
  }
  </code></pre>