我有一个数组如下
var x = new int[] { 1,2,3 };
并给出一个限制
int limit=2;
我必须找到一个组合
1+2 = 3
1+3 = 4
2+3 = 5.
如果数组说
var x = new int[] { 1,2,3,4,5,6};
并给出一个限制
int limit=3;
组合应该是
1+2+3 = 6
1+2+4 = 7
1+2+5 = 8
1+2+6 = 9
2+3+4 = 9
2+3+5 = 10
2+3+6 = 11
...........
............
等等
怎么做?
我的错误尝试
var x = new int[] {1,2,3};
int limit = 2;
var m = from a1 in x
from a2 in x
select new
{
P1 = a1 ,
P2 = a2,
P3 = a1+a2
};