int size = 7;
// read the text and create lists for each file
var listA = ReadFileToList("D:\\user\\A.txt");
var listB = ReadFileToList("D:\\user\\B.txt");
var listC = ReadFileToList("D:\\user\\C.txt");
var listD = ReadFileToList("D:\\user\\D.txt");
// get the combinations from lists
var combinations = (from a in listA
from b in listB
from c in listC
from d in listD
select new[] { a, b, c, d })
.Take(size)
.ToList();
if you need randomly select items
var randomCombinations = (from a in listA
from b in listB
from c in listC
from d in listD
select new[] { a, b, c, d })
.OrderBy(n => Guid.NewGuid())
.Take(size)
.ToList();
You need helper method like below
public List<string> ReadFileToList(string path)
{
List<string> temp = new List<string>();
using (StreamReader r = new StreamReader(path))
{
string line;
if ((line = r.ReadLine()) != null)
{
temp =line.Split(',').ToList();
}
}
return temp;
}
UPDATE
you can print result as below
Console.WriteLine(string.Join("|",
randomCombinations.Select(c => string.Join(",", c))));
Result will show something like below
A,D,E,G|A,D,F,G|B,D,F,G|B,C,E,G|A,C,E,G|A,C,F,G|B,C,F,G
OR Extending your code as below
foreach (var item in combinations) { Console.WriteLine(string.Join(",", item)); }