title: Object reference not set to an instance of an object exception when assigning a list to a listbox
body: <p>I wrote the following method to load a list box with values that have not been loaded already but I am getting an Object reference not set to an instance of an object exception when assigning the following. Any information would be helpful. Thanks.  </p>
  
  <pre><code>lbxCabinetName.Items.Add(cabinetsCurrentNotUsed[i].ToString());
  
  // Defined outside a method
  List&lt;string&gt; cabinetsCurrentNotUsed; 
  
  // Set value in the constructor
  cabinetsCurrentNotUsed = new List&lt;string&gt;();
  </code></pre>
  
  <p>Here is the whole procedure.</p>
  
  <pre><code>    private void selectCabinetToAdd()
      {
  
          // Loop through all server and form cabinet types to see if there are matches
          for (int x = 0; x &lt; opticalFile.serverCabinetNames.Count; x++)
          {
              bool cabinetExists = false;
              for (int i = 0; i &lt; opticalFile.CabinetValues.Count; i++)
              {
                  if (opticalFile.serverCabinetNames[x].ToString() == opticalFile.CabinetValues[i].ToString())
                  {
                      cabinetExists = true;
                  }
              }
              // Add cabinets not used to cabinetsCurrentNotUsed List
              if (!cabinetExists)
              {
                  cabinetsCurrentNotUsed.Add(opticalFile.serverCabinetNames[x].ToString());
              }
          }
  
          // Send cabinetsCurrentNotUsed List to list box
          for (int i = 0; i &lt; cabinetsCurrentNotUsed.Count; i++)
          {
              lbxCabinetName.Items.Add(cabinetsCurrentNotUsed[i].ToString());
          }
      }
  </code></pre>