title: Adding to a list inside a class
body: <p>I have this class</p>
  
  <pre><code>public class User
  {
     private string _name;
     public string UserName { get; set; }       
     public List&lt;int&gt; ControlNumber { get; set; }
     public User (string username)
     {
         _name = username;
     }
     public User()
     {
     }
  
  }
  </code></pre>
  
  <p>And this function that fills the class.</p>
  
  <pre><code>User UserClass = new User(e.Key); //e.Key = user's name
  
  public static void FillUserListClass(DataTable dt, ref UserClass)
  
  {
      try
      {
  
          for (int ctr = 0; ctr &lt; dt.Rows.Count; ctr++)
          {
              var row = dt.Rows[ctr];
              var userName = row["User"].ToString();
  
              if (UserList.ContainsKey(userName))
              {
                  UserList[userName].Add(Convert.ToInt32(row["ControlNumber"]));
              }
              else
              {
                  _user.UserName = row["User"].ToString();
                  _user.ControlNumber.Add(Convert.ToInt32(row["ControlNumber"]));
  
              }
                //print out
              Console.WriteLine("UserList Class: ");
              Console.WriteLine(_user.UserName);
              Console.WriteLine(_user.ControlNumber);
  
  
          }
      }
      finally
      {
          //conn.Close();
      }
  
  }
  </code></pre>
  
  <p>However, at the <code>_user.ControlNumber.Add(Convert.ToInt32(row["ControlNumber"]));</code> line I get the "Object reference not set to an instance of an object." error. Any help?</p>
  
  <p>What i'm trying to do is create a class for each user that contains the user's control numbers. I then want all of these classes to be placed into a dictionary for reference.</p>