title: How to select certain strings (by index) from a list in a list with linq?
body: <p>I have an object that looks like this.</p>
  
  <pre><code>List&lt;List&lt;string&gt;&gt; MyData;
  </code></pre>
  
  <p>The inner <code>List&lt;string&gt;</code> can contain an undefined number of strings but the number is always larger than 0.<br>
  In an other object I have the index numbers of the strings I want to select.
  The Index number is located in MyObject.Number;</p>
  
  <p>How can I get a <code>List&lt;List&lt;string&gt;&gt;</code> object with only the strings present at the given indexes?</p>
  
  <p>I tried the following:  </p>
  
  <pre><code>List&lt;List&lt;string&gt;&gt; test = new List&lt;List&lt;string&gt;&gt;();
  List&lt;MyObject&gt;.ForEach(p =&gt; test.Add(MyData.Select(q =&gt; q[p.Number]).ToList()));
  </code></pre>
  
  <p>This didn't worked out well since I got a list with the string seperate in lists.</p>
  
  <p>Example:<br>
  I got a <code>List</code> with 100 <code>List&lt;string&gt;</code> in it. The <code>List&lt;string&gt;</code> contains 5 strings.
  <code>List&lt;MyObject&gt;</code> tells me he has the indexes 0 and 2.<br>
  The code I tried returned to me a list with two lists in it. The first list contained all the strings in 0 location of <code>List&lt;string&gt;</code>, the second list all the strings in the 2 location of <code>List&lt;string&gt;</code>.
  I wanted a list with 100 lists and in every list 2 strings.</p>
  
  <p>Please help me to solve this problem.</p>
  
  <p>Feel free to ask more information if needed.</p>
  
  <p><strong>SOLUTION:</strong>  </p>
  
  <pre><code>List&lt;List&lt;string&gt;&gt; MyResult = MyData.Select(l =&gt; MyObjects.Select(p =&gt; p.Number).ToList().Select(i =&gt; l[i]).ToList()).ToList();
  </code></pre>