title: working with a list across methods in c# using winforms
body: <p>I am working on a problem where I load a text file into a string list and display in a listbox (which I have done) but I now want a button event to place the contents of the list in a second listbox which is just coming up blank. I can easily do this in VB but I'm fairly new to C# and realise I am probably missing something obvious.</p>
  
  <pre><code>namespace texttoarray
  {
  
  
      public partial class Form1 : Form
      {
  
          public int counter;
          public List&lt;string&gt; finalList;
  
          public Form1()
          {
              InitializeComponent();
              List&lt;string&gt; finalList = AddToList();
  
          }
  
          public List&lt;string&gt; AddToList()
          {
              counter = 0;
              string line;
              List&lt;string&gt; list = new List&lt;string&gt;();
              System.IO.StreamReader file = new System.IO.StreamReader(@"list.txt");
              while ((line = file.ReadLine()) != null)
              {
                  listBox1.Items.Add(line);
                  list.Add(line);
                  counter++;
              }
  
  
              //listBox2.DataSource = list;
  
              MessageBox.Show(counter.ToString());
              return list;
          }
  
  
          public void button1_Click(object sender, EventArgs e)
          {
              listBox2.DataSource = finalList;
  
          }
  
  
      }
  
  
  }
  </code></pre>