While initializing, it says "Object reference not set to an instance of an object"
<p>I'm totally new to C# and I'm having an error that I can't guess why its happening. This is the context:</p>

<p>I have a DataPair class, wich is just that, a pair of data (string, float). I also have another class DataSet wich is an array of DataPairs.</p>

<p>DataSet has two private members:</p>

<pre><code>private DataPair [] _datapair;
private int _size;
</code></pre>

<p>The constructor of DataSet does nothing with _datapair and set _size to 0.</p>

<p>I fill the DataSet with a method Append, wich does something like this:</p>

<pre><code>public void Append(DataPair pair)
{
    _datapair[_size] = new DataPair(pair);
    _size++;
}
</code></pre>

<p>I call Append from another method, FillFromFile:</p>

<pre><code>public void FillFromFile(string filepath)
{
    try
    {
        if (System.IO.File.Exists(filepath))
        {
            System.IO.StreamReader sr = new System.IO.StreamReader(filepath);
            string[] currentdata;
            while (sr.Peek() &gt;= 0)
            {
                currentdata = sr.ReadLine().Replace(',', '.').Trim().Split(';');
                this.Append(new DataPair(currentdata[0],  System.Convert.ToSingle(currentdata[1])));
            }

            sr.Close();
        }
    }
    catch (Exception e)
    {
        Console.WriteLine("Error in datafile: {0}", e.ToString());
    }
}
</code></pre>

<p>It seems that it should work: It creates (new) a new DataPair for each Append. </p>

<p>But I get this error when executing: "Object reference not set to an instance of an object" in function Append.</p>

<p>What is happening?</p>

<p>Thanks!</p>
