I'm trying to filter the following list:
List<List<int>> list = new List<List<int>>()
{
new List<int>(){1,2,3,4,5},
new List<int>(){6,7,5,4,5},
new List<int>(){1,3,3,222,1}
}
My filter condition should be: "include only odd numbers", so my list shouldn't have any even numbers after the filter is applied.
My Attempt:
list = list.Where(x => x.Where(y => y%2 == 1).ToList()).ToList()
Desired Output:
List<List<int>> list = new List<List<int>>()
{
new List<int>(){1,3,5},
new List<int>(){7,5,5},
new List<int>(){1,3,3,1}
}
I know how to use Linq on single-dimensional collections, but not sure how to make this one work.
Any ideas?