Error Loading File
<p>I made big progress, but now i have a problem with the loading of a file. Here is the class with the file-loading method again:</p>

<pre><code>public class BunchOfDeliverables
{
    private List&lt;Person&gt; myPersons;
    private List&lt;Deliverable&gt; myDeliverables;

    public BunchOfDeliverables()
    {
        this.myPersons = new List&lt;Person&gt;();
        this.myDeliverables = new List&lt;Deliverable&gt;();
    }

    public List&lt;Person&gt; Persons { get { return this.myPersons; } }
    public List&lt;Deliverable&gt; Deliverables { get { return this.myDeliverables; } }

    public void LoadPersonsFromFile(String filename)
    {
        StreamReader sr = null;
        try
        {
            sr = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read));
            String name, street, housenr, postalcode, city;
            name = sr.ReadLine();
            while (name != null)
            {
                street = sr.ReadLine();
                housenr = sr.ReadLine();
                postalcode = sr.ReadLine();
                city = sr.ReadLine();
                this.myPersons.Add(new Person(name, street, Convert.ToInt32(housenr), postalcode, city));
                name = sr.ReadLine();
                name = sr.ReadLine(); //and again read a line, because of the delimiter (line with the stars)
            }
        }
        catch (IOException) { }
        finally
        {
            if (sr != null) sr.Close();
        }
    }

    public void LoadDeliverablesFromFile(String filename)
    {
        StreamReader sr = null;
        try
        {
            sr = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read));
            String s;
            s = sr.ReadLine();
            while (s != null)
            {
                String[] items = s.Split();
                this.myDeliverables.Add(new Deliverable(Convert.ToInt32(items[0]), Convert.ToInt32(items[1]), this.myPersons[Convert.ToInt32(items[2])]));
                s = sr.ReadLine();
            }
        }
        catch (IOException) { }
        finally
        {
            if (sr != null) sr.Close();
        }
    }


    public void AddPerson(Person p)
    {
        this.myPersons.Add(p);
    }


    public Deliverable FindDeliverable(int id)
    {
        foreach (Deliverable d in this.myDeliverables)
        {
            if (d.ID == id)
            {
                return d;
            }
        }
        return null;
    }

    public void AddDeliverable(Deliverable d)
    {
        if (FindDeliverable(d.ID) == null)
        {
            myDeliverables.Add(d);
        }
        else
        {
            throw new Exception("Be aware: nothing is added!!!");
        }

    }
</code></pre>

<p>And here - in the form i`ve initialized them:</p>

<pre><code>public partial class Form1 : Form
{
    BunchOfDeliverables d;
    public Form1()
    {
        InitializeComponent();
        d = new BunchOfDeliverables();
        d.LoadDeliverablesFromFile("../../data/deliverables.txt");
        d.LoadPersonsFromFile("../../data/persons.txt");
    }

    private void button1_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        foreach (Person per in d.Persons)
        {

            listBox1.Items.Add(per);
        }


    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void ViewDeliv_Click(object sender, EventArgs e)
    {
        listBox1.Items.Clear();
        foreach (Deliverable deliv in d.Deliverables)
        {

            listBox1.Items.Add(deliv);
        }
    }
</code></pre>

<p>Now for the Persons loading file it works like a charm, nothing goes wrong, but once i try to load the Deliverables file the following error occurs:</p>

<blockquote>
  <p>Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index" on this line:</p>
  
  <p>"this.myDeliverables.Add(new Deliverable(Convert.ToInt32(items[0]), Convert.ToInt32(items[1]), this.myPersons[Convert.ToInt32(items[2])]));" </p>
</blockquote>

<p>Here is how the deliverables file is structured with a small example(without the empty lines):</p>

<pre><code>1 350 1
2 700 5
3 360 7
4 360 6
</code></pre>

<p>Any help would be appreciated!</p>
