I have those functions
public static IEnumerable<IEnumerable<T>> GetPermutations<T>(IEnumerable<T> items, int count)
{
int i = 0;
foreach (var item in items)
{
if (count == 1)
yield return new T[] { item };
else
{
foreach (var result in GetPermutations(items.Skip(i + 1), count - 1))
yield return new T[] { item }.Concat(result);
}
++i;
}
}
public static List<List<int>> GetAllValidCombinations(List<int> items)
{
var finalList = new List<List<int>>();
switch (items.Count)
{
case 1:
finalList.Add(items);
break;
case 3:
finalList.AddRange(GetPermutations(items, 2));
finalList.AddRange((List<List<int>>)GetPermutations(items, 3));
break;
}
return finalList;
}
and i want to get an List<List> from GetAllValidCombinations.
In the case 3 of GetAllValidCombinationsin the first line im getting: Error CS1503 Argument 1: cannot convert from 'System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable>' to 'System.Collections.Generic.IEnumerable<System.Collections.Generic.List>'
and if i try the second line im getting error Specified cast is not valid
How i can do this cast in one line?