title: Is this really not a legal way to initialize a list in C#
body: <p>I'm trying to initialize a string list to use in a later method. I don't know what size the list needs to be because the data sets that will be passed to the program are not consistently sized. Because of this, I'm dynamically adding items to the list. However, when I initialize the list in the space above what would be considered <code>main()</code> like this,</p>
  
  <pre><code>List&lt;string&gt; studentData;
  </code></pre>
  
  <p>and call it in a public method like this,</p>
  
  <pre><code>studentData.AddRange(student); // Student is an array
  </code></pre>
  
  <p>I get an exception that says, </p>
  
  <blockquote>
    <p>System.NullReferenceException: 'Object reference not set to an instance of 
    an object' studentData was null.</p>
  </blockquote>
  
  <p>but earlier in my code I called initialized a different list like this and it worked just fine,</p>
  
  <pre><code>List&lt;string&gt; fileInput; // Holds comma delimited file text
  .
  . 
  .
  fileInput = text.Split(',').ToList();`
  </code></pre>
  
  <p>So then I went to <a href="https://www.dotnetperls.com/initialize-list" rel="nofollow noreferrer">DotNetPerls</a> to figure out how to initialize a non empty list. Per the code examples this should have worked,</p>
  
  <pre><code>List&lt;string&gt; studentData = new List&lt;string&gt;();
  studentData.Add("Thing");
  </code></pre>
  
  <p>but <code>studentData</code> got green underlined with warning text </p>
  
  <blockquote>
    <p>studentData is never assigned to, and will always have its default value 
    null.</p>
  </blockquote>
  
  <p>and <code>studentData.Add("Thing");</code> got red underlined with error text</p>
  
  <blockquote>
    <p>The name 'studentData.Add' doesn't exist in the current context. 
    The name 'studentData' doesn't exist in the current context.</p>
  </blockquote>
  
  <p>and <code>("Thing")</code> was handled separately as well.</p>
  
  <blockquote>
    <p>Type expected.<br>
    Tuple must contain at least two elements.
    ) expected.
    Invalid token '"Thing"' in class, struct, or interface member declaration</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/Wcq1O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wcq1O.png" alt="enter image description here"></a></p>
  
  <p>I'm still fairly new to C# and none these errors makes sense to me. What am I doing wrong here?</p>