日期:2014-05-18  浏览次数:21127 次

两个一维数组减去一个固定值3,得到的数组怎么保存?
double [] z;
double [] x = {31.01, 31, 31.09};
double [] y = { 121.2, 121.4, 121.14};
  for (int i = 0; i < x.Length ; i++)
  {
  for (int j = 0; j < y.Length; j++)
  {
  z= Convert.ToDouble(x.ElementAt(i)) - Convert.ToDouble(3)+Convert.ToDouble(y.ElementAt(j)) - Convert.ToDouble(3);这里保存不了z,z应该是一个3维数组?
  }
  }

------解决方案--------------------
C# code
double[] x = { 31.01, 31, 31.09 };
                double[] new_array = x.Select(a=>a+3).ToArray();

------解决方案--------------------
double[] x = { 31.01, 31, 31.09 };
double[] z = { 0, 0, 0 };
double[] t = new double[x.Length];

for (int i = 0; i <= x.Length-1 ; i++)
{
z[i] = x[i] + 3.0;
t[i] = x[i] + 4.0;
}
------解决方案--------------------
探讨
double [] x = {31.01, 31, 31.09};
简单点,我想一维数组分别加个固定值3,怎么得到的新数组?