title: C# - How to write a List<List<string>> to CSV file?
body: <p>I'd like to write some data to a CSV file using C#.</p>
  
  <p>Here's my code at the moment : </p>
  
  <pre><code>int length = readData.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Length;
  
  List&lt;List&lt;string&gt;&gt; dataList = new List&lt;List&lt;string&gt;&gt;();
  
  foreach (string line in readData.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
  {
      List&lt;string&gt; partsLine = new List&lt;string&gt;();
      partsLine.AddRange(line.Split('\t'));
      dataList.Add(partsLine);
  }          
  </code></pre>
  
  <p>So, I'm splitting all the data in lines.</p>
  
  <p>Then I split each line with '\t' separator, and add each part of the line in a list.</p>
  
  <p>And at the end I have a list containing all the lists of split lines.</p>
  
  <p>So the list looks like : </p>
  
  <ul>
  <li>List1 {txt1, txt 2} = first line</li>
  <li>List2 {txt3, txt 4, txt 5, txt 6} = second line</li>
  <li>List3 {txt7, txt 8, txt 9, txt 10} = third line</li>
  <li>List4 {txt 11, txt 12} etc.</li>
  </ul>
  
  <p>All of the lists don't have the same lenght as you can see.</p>
  
  <p>What I'd like to do is writing all the lists to a CSV file.</p>
  
  <p>Each list would fill a row and a certain number of columns, depending of the lenght of the list (i.e. txt1 should be (row1, col1), txt2 should be (row1, col2), txt3 should be (row2, col1), txt4 would be (row2, col2)...).</p>
  
  <p>How can I do that ?</p>
  
  <p>Thanks</p>