I have text files in a folder such as f1.txt,f2.txt,....f15.txt. I want to get the combination of them that has a length 2.
The final result should be
{f1.txt, f2.txt}, {f1.txt, f3.txt}....
I used the code
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 })); } Then call it from the main method.
string[] files = Directory.GetFiles(@"C:\Users\Downloads\Samples", "*.txt"); IEnumerable<IEnumerable<string>> filescombination = GetKCombs(files, 2); But why I got nothing?
EDIT:
foreach(var x in filescombination) { Console.WriteLine(x); } In the immediate window, we have
?x {System.Linq.Enumerable.ConcatIterator<string>} first: null second: null
x?