title: While initializing, it says "Object reference not set to an instance of an object"
body: <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, which is just that, a pair of data (string, float). I also have another class DataSet which 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, which 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(&quot;Error in datafile: {0}&quot;, 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:</p>
  <blockquote>
  <p>&quot;Object reference not set to an instance of an object&quot; in function Append.</p>
  </blockquote>
  <p>What is happening?</p>