title: Load back a textfile into a List<Class>
body: <p>I'm currently stuck with a small problem.</p>
  
  <p>My program currently outputs a return value and puts it in a listbox with this method:</p>
  
  <pre><code>        public override string ToString()
      {
          CheckKamer();
          if (IsKamerBezet == true)
          {
              return $"Kamer: {Nummer} is bezet";
          }
          else
          {
              return $"Kamer: {Nummer} is vrij";
          }
      }
  </code></pre>
  
  <p>after that my program saves the return values provided by the method in a .txt file with this method:</p>
  
  <pre><code>private void ReserveringText()
      {
          using (System.IO.StreamWriter file =
          new System.IO.StreamWriter(filepath, true))
              file.WriteLine(reserveringLB.Items.ToString());
          System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(filepath);
          foreach (var item in reserveringLB.Items)
          {
              SaveFile.WriteLine(item.ToString());
          }
      }
  </code></pre>
  
  <p>Now when I restart my program it reads the lines put in the .txt file and sets it back in the listbox, with another simple method:</p>
  
  <pre><code>        private void LaadItems()
      {
          var lines = File.ReadAllLines(filepath);
          reserveringLB.DataSource = lines;
      }
  </code></pre>
  
  <p>But whenever I try to add a new guest to my hotel, it says the object reference isnt set to an instance of the object, because it loads it from the .txt file and not from the class list I used to load it from.</p>
  
  <p>My guest is added to the class here:</p>
  
  <pre><code>private void reserveerBtn_Click(object sender, EventArgs e)
  {
      Gast gast = new Gast(tbNaam1.Text, cbOntbijt1.Checked, cbDiner1.Checked, (Model.Enum.Geslacht)cbGeslacht1.SelectedValue);
      Reservering reservering = new Reservering(vrijekamer, dateTimePicker1.Value, dateTimePicker2.Value, gast);
                      gast.Reservering = reservering;
      admin.VoegGastToe(gast);
       admin.VoegReserveringToe(reservering);
  }
  </code></pre>
  
  <p>Could anyone help me out and tell me how I'd be able to let the program load the .txt file, and put that back into the List so I can actually add a guest to the program.</p>
  
  <p>If anything is unclear please let me know, I'll be looking at this post alot so I can immediatly change it / add something if u guys need anything.</p>