110,537
社区成员
发帖
与我相关
我的任务
分享
var result = from a in arr1
from b in arr2
from c in arr3
select String.Format("{0}*{1}*{2} = {3}", a, b, c, a * b * c);
如果确定数组数量我就这么写了…… private void Load()
{
var dics = new Dictionary<string, decimal[]>();
dics.Add("x001", new[] { 1m });
dics.Add("x002", new[] { 2, 2.5m, 2.2m });
dics.Add("x003", new[] { 3, 3.2m });
//...
/*
* 参数1:dics 是变量,格式就是<string, decimal[]>,每条数据里面的 decimal[] 是动态的
* 参数2:combination 是变量,意思:M串1(2:表示任意两个数相乘;3:表示任意三个数相乘;4:表示任意四个数相乘;同一数组里面的数不相乘)
*
* 结果:
*
GetHtml(dics, 2)
*
a001[1]*a002[2]=2;
a001[1]*a002[2.5]=xx;
a001[1]*a002[2.2]=xx;
a001[1]*a003[3]=xx;
a001[1]*a003[3.2]=xx;
a002[2]*a003[3]=2;
a002[2]*a003[3.2]=xx;
a002[2.5]*a003[3]=2;
a002[2.5]*a003[3.2]=xx;
a002[2.2]*a003[3]=2;
a002[2.2]*a003[3.2]=xx;
*
GetHtml(dics, 3)
*
a001[1]*a002[2]*a003[3]=xx;
a001[1]*a002[2.5]*a003[3]=xx;
a001[1]*a002[2.2]*a003[3]=xx;
a001[1]*a002[2]*a003[3.2]=xx;
a001[1]*a002[2.5]*a003[3.2]=xx;
a001[1]*a002[2.2]*a003[3.2]=xx;
*/
}
private void GetHtml(Dictionary<string, decimal[]> dics, int combination)
{
//...
}
* 参数1:dics 是变量,格式就是<string, decimal[]>,每条数据里面的 decimal[] 是动态的
* 参数2:combination 是变量,意思:M串1(2:表示任意两个数相乘;3:表示任意三个数相乘;4:表示任意四个数相乘;同一数组里面的数不相乘)//输出结果
i = 0;
foreach (var x in a)
{
Console.Write(string.Format("{0}",x.ToString().PadLeft(10)));
i++;
if (i % 3 == 0)
Console.WriteLine();
}
6 7.0 6.4
7.5 8.75 8.00
6.6 7.70 7.04
9.0 10.50 9.60
11.25 13.125 12.000
9.90 11.550 10.560
7.2 8.40 7.68
9.00 10.500 9.600
7.92 9.240 8.448
var dics = new Dictionary<string, decimal[]>();
dics.Add("001", new [] { 1, 1.5m, 1.2m });
dics.Add("002", new [] { 2, 2.5m, 2.2m });
dics.Add("003", new [] { 3, 3.5m, 3.2m });
//...数组可以无限多
var a = dics["001"].ToList();
int i = 0;
foreach (var b in dics.Values)
{
if (i > 0)
{
a = (from x in a
from y in b
select x * y).ToList();
}
i++;
}
double[] a3 = { 1, 2 };
double[] b3 = { 3, 4 };
double[] result = a3.Zip(b3, (x, y) => x * y).ToArray();
一组组数据乘下去