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