Hey! I really need some help.
I have a function for generating combinations. Here it is
public static IEnumerable<IEnumerable<T>> GetKCombs<T>(IEnumerable<T> list, int length) where T : IComparable
{
if (length == 1) return list.Select(t => new T[] { t });
return GetKCombs(list, length - 1)
.SelectMany(t => list.Where(o => o.CompareTo(t.Last()) > 0),
(t1, t2) => t1.Concat(new T[] { t2 }));
}
usage is:
var result = GetKCombs(new int[] {1,2,3,4,5},3);
Problem is following: i want to convert var to List<string>, and .ToList() doesn`t work properly.
Please, help.
What I have tried:
Well, i`ve tried to do use method .ToList():
result.ToList()
but it contains something strange.
Secondly, i`ve written following:
List<string> vectors = new List<string>();
foreach (var res in result)
vectors.Add(res.ToString());
but it didn`t work properly too.