private void button1_Click(object sender, EventArgs e) { // load OpenFileDialog b = new OpenFileDialog(); if (b.ShowDialog() == DialogResult.OK) { StreamReader a = new StreamReader(b.FileName); int numofyears = int.Parse(a.ReadLine()); for (int i = 0; i != numofyears; i++) { year c = new year(); c.loadsubjects(ref a); years.Add(c); } a.Close(); updateyear(); } }