From the given set
{1,2,3,4,5,6,7,8,99,89}
What is the way to get all possible two numbers subset using LINQ?
(i.e) {1,2},{1,3},{1,4} .....
From the given set
{1,2,3,4,5,6,7,8,99,89}
What is the way to get all possible two numbers subset using LINQ?
(i.e) {1,2},{1,3},{1,4} .....
cross join?
var data = new[] {1,2,3,4,5,6,7,8,99,89};
var qry = from x in data
from y in data
where x < y
select new {x,y};
foreach (var pair in qry) {
Console.WriteLine("{0} {1}", pair.x, pair.y);
}
For triples:
var data = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 99, 89 };
var qry = from x in data
from y in data
where x < y
from z in data
where y < z
select new { x, y, z };
foreach (var tuple in qry) {
Console.WriteLine("{0} {1} {2}", tuple.x, tuple.y, tuple.z);
}
This link doesn't support LINQ queries, but I consider it related and relevant: Permutations, Combinations, and Variations using C# Generics